var ds;
var ds2;
var helper = specHelper;
var insertForm;
var updateForm;
var form;
var win;
var processDs;
var processDs2;
var id;
var id2;
var grid;
var grid2;
var timeId, timeId2, timeId3, timeId4, timeId5, timeId6, timeId7, timeId8, timeId9, timeId10, timeId11, timeId12, timeId13, timeId14, timeId15, timeId16, timeId17, timeId18, timeId19;
var flag = 0;
var processDsDirty = -1;
var processDs2Dirty = -1;

var dsDirty = false;
var ds2Dirty = false;
var procedureDirty = -1;
var procedure = 0;
var processProcedure = 0;
var dataForm;
var dataGrid;
var cm;
var showDs;
var selected = false;
var loadmask;
var WAITTIME = 1000;
var runningSm;
var mapWin;
var mapGrid;
var mapForm;
var mapDs;
var MAP;
var procedureWin;
var procedureForm;
var ALLDIRTY = 100;
var runningGrid;
var runningDs;
var runningMainDs;
var processSaveStart = 0;
var processHopeProcedure = 0;
var procedureDsArr1 = [["读取开模规格", 1], ["创建加工细节", 2], ["读取配方价格", 3],
		["读取未磨成品率", 4], ["读取已磨成品率", 5], ["读取毛重", 6], ["读取前道收得率", 7],
		["读取废品率", 8], ["读取前道费用", 9], ["读取包装费", 10]];
var procedureDsArr2 = [["读取加工后规格", 1], ["读取加工面积", 2], ["读取加工单价", 3],
		["读取加工成品率", 4], ["读取加工数量", 5]];
var procedureDsArr3 = [["未磨默认成品率", 1], ["已磨默认成品率", 2], ["前道默认收得率", 3],
		["毛重理论值", 4], ["加工默认成品率", 5], ["勿点,无效", 0]];
var rotateSpecArr = [];
var transnumArr = [];
var rotateValue;
var rotateStop = true;
var hasRotate = false;
var procedureWinFlag = 0;
var MAXFEE = 0.1;
var hopeOrReal = ["目标", "实际"];
var stepStore = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
						url : '../orderJiaGongIndex.do?action=step'
					}),
			reader : new Ext.data.JsonReader({
						totalProperty : 'totalProperty',
						root : 'root'
					}, [{
								name : 'processName'
							}, {
								name : 'processPos'
							}])
		});
var disableRecord = Ext.data.Record.create([{
			name : 'tabName'
		}, {
			name : 'tabId'
		}]);
var procedureDs = new Ext.data.SimpleStore({
			fields : ['step', 'pos'],
			data : procedureDsArr1
		});
var transnumDs = new Ext.data.SimpleStore({
			fields : ['delvnum', 'custid', 'transnum'],
			data : transnumArr
		});
var schemeArr = [];
var schemeDs = new Ext.data.SimpleStore({
			fields : ['scheme', 'value'],
			data : transnumArr
		});
var transnumError = false;
var mapArr = [];
var YIMO_MJG = false;
var orderExcel = new OrderExcel();
var osmRecord = Ext.data.Record.create([{
			name : 'id'
		}, {
			name : 'spec'
		}, {
			name : 'factory'

		}, {
			name : 'transnum'
		}, {
			name : 'ordernum'
		}, {
			name : 'ssign'
		}, {
			name : 'ssign_yz',
			mapping : 'ssign_yz'
		}, {
			name : 'grossweight',
			mapping : 'grossweight'
		}, {
			name : 'qiandao_yield',
			mapping : 'qiandao_yield'
		}, {
			name : 'yimo',
			mapping : 'yimo'
		}, {
			name : 'weimo',
			mapping : 'weimo'
		}, {
			name : 'feipin',
			mapping : 'feipin'
		}, {
			name : 'qiandao_cost',
			mapping : 'qiandao_cost'
		}, {
			name : 'product_cost_before',
			mapping : 'product_cost_before'
		}, {
			name : 'specType',
			mapping : 'specType'
		}, {
			name : 'processScheme',
			mapping : 'processScheme'
		}, {
			name : 'plate',
			mapping : 'plate'
		}, {
			name : 'baozhuangfei',
			mapping : 'baozhuangfei'
		}, {
			name : 'houdao_yield',
			mapping : 'houdao_yield'
		}, {
			name : 'product_cost_last',
			mapping : 'product_cost_last'
		}, {
			name : 'date1',
			mapping : 'date1'
		}, {
			name : 'ordercost',
			mapping : 'ordercost'
		}, {
			name : 'lirun',
			mapping : 'lirun'
		}, {
			name : 'bz',
			mapping : 'bz'
		}, {
			name : 'maker',
			mapping : 'maker'
		}, {
			name : 'makeDate',
			mapping : 'makeDate'
		}, {
			name : 'type',
			mapping : 'type'
		}, {
			name : 'peifang',
			mapping : 'peifang'
		}, {
			name : 'spec_yz',
			mapping : 'spec_yz'
		}, {
			name : 'month1',
			mapping : 'month1'
		}, {
			name : 'year1',
			mapping : 'year1'
		}, {
			name : 'status',
			mapping : 'status'
		}]);
var cache_search;
var OSM;
Ext.onReady(function() {
			var arr = window.location.href.split('&');

			if (arr.length < 2) {
				id = "";
				id2 = "";
				Ext.Msg.confirm("提示",
						"请先选择发货信息或者选择一个旧订单,'是'--重新选择发货订单，'否'--进入查询界面",
						function(button) {
							if (button == 'yes') {
								window.location.href = "orderInf.jsp";
							} else
								window.location.href = "orderSearchIndex.jsp";

						})
			} else {
				id = arr[0].split('=')[1];
				id2 = arr[1].split('=')[1];
				initData();
				initAutoSave();
				initListeners();
			}

		});
function initListeners() {
	grid.on("cellclick", function(grid, row, col) {
				if (col < 2)
					return;
				var sm = grid.getSelectionModel();
				sm.selectRow(row);

				runningSm = sm;
				runningGrid = grid;
				runningDs = processDs;
				runningMainDs = ds;
				processAction();

			});
	grid2.on("cellclick", function(grid2, row, col) {
				if (col < 2)
					return;
				var sm = grid2.getSelectionModel();
				sm.selectRow(row);
				runningSm = sm;
				runningGrid = grid2;
				runningDs = processDs2;
				runningMainDs = ds2;
				processAction();
			});
}
function initAutoSave() {// 自动保存。

	timeId = window.setInterval("saveOrderSumMain()", 50000);
	timeId2 = window.setInterval("saveOrderSumSub()", 50000);
}
function saveOrderSumMain() {
	// window.clearInterval(timeId);不清零的话，就会反复执行。
	if (flag < 3)
		return;
	// alert("save");
	if (dsDirty) {// 如果ds数组已经修改过了。则进行保存。
		dsDirty = false;

		orderSumMain.updateRecord(convert(ds.getAt(0)), function(_ret) {

					;
				})
	}
	if (ds2Dirty) {
		ds2Dirty = false;
		orderSumMain.updateRecord(convert(ds2.getAt(0)), function(_ret) {
					;
				})
	}
}
function saveOrderSumSub() {
	if (flag < 3)
		return;
	if (processDsDirty > -1)
		if (processDsDirty) {
			dwr.engine.setAsync(false);
			var num = processDsDirty - 1;
			processDsDirty = -1;
			if (processSaveStart > 0) {
				processDs.each(function(rec) {
							if (rec)
								orderSumSub.updateRecord(convert(rec),
										function(ret) {

										});
						});
				processSaveStart = 0;
			} else {
				if (processDs.getCount() > 0)
					orderSumSub.updateRecord(convert(processDs.getAt(num)),
							function(ret) {

							});
			}

			dwr.engine.setAsync(true);
		}
	if (processDs2Dirty > -1)
		if (processDs2Dirty) {
			dwr.engine.setAsync(false);
			var num = processDs2Dirty - 1;
			processDs2Dirty = -1;
			if (processSaveStart > 0) {
				processDs2.each(function(rec) {
							if (rec)
								orderSumSub.updateRecord(convert(rec),
										function(ret) {
										});
						});
				processSaveStart = 0;

			} else {
				if (processDs2.getCount() > 0)
					orderSumSub.updateRecord(convert(processDs2.getAt(num)),
							function(ret) {

							});
			}
			dwr.engine.setAsync(true);
		}
}
function convert(_rec) {
	var obj = {};

	for (var property in _rec.data) {
		if (/status/.test(property))
			continue;
		var property2 = property.replace('2', '');
		if (/(date)|(Date)/.test(property)
				&& (!/(update)|(Update)/.test(property)))
			obj[property2] = Date.parseDate(_rec.data[property], 'Y-m-d');
		else
			obj[property2] = _rec.data[property];
	}
	return obj;
}
function initData() {
	ds = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : '../ordersummain.do?action=list&id=' + id
						}),

				reader : new Ext.data.JsonReader({
							root : 'root'
						}, [{
									name : 'id',

									mapping : 'id'
								}, {
									name : 'spec',
									mapping : 'spec'
								}, {
									name : 'factory',
									mapping : 'factory'

								}, {
									name : 'transnum',
									mapping : 'transnum'
								}, {
									name : 'ordernum',
									mapping : 'ordernum'
								}, {
									name : 'ssign',
									mapping : 'ssign'
								}, {
									name : 'ssign_yz',
									mapping : 'ssign_yz'
								}, {
									name : 'grossweight',
									type : 'float',
									mapping : 'grossweight'
								}, {
									name : 'qiandao_yield',
									type : 'float',
									mapping : 'qiandao_yield'
								}, {
									name : 'yimo',
									type : 'float',
									mapping : 'yimo'
								}, {
									name : 'weimo',
									type : 'float',
									mapping : 'weimo'
								}, {
									name : 'feipin',
									type : 'float',
									mapping : 'feipin'
								}, {
									name : 'qiandao_cost',
									type : 'float',
									mapping : 'qiandao_cost'
								}, {
									name : 'product_cost_before',
									type : 'float',
									mapping : 'product_cost_before'
								}, {
									name : 'specType',
									mapping : 'specType'
								}, {
									name : 'processScheme',
									mapping : 'processScheme'
								}, {
									name : 'plate',
									mapping : 'plate'
								}, {
									name : 'baozhuangfei',
									type : 'float',
									mapping : 'baozhuangfei'
								}, {
									name : 'houdao_yield',
									type : 'float',
									mapping : 'houdao_yield'
								}, {
									name : 'product_cost_last',
									type : 'float',
									mapping : 'product_cost_last'
								}, {
									name : 'date1',

									mapping : 'date1'
								}, {
									name : 'ordercost',
									type : 'float',
									mapping : 'ordercost'
								}, {
									name : 'lirun',
									type : 'float',
									mapping : 'lirun'
								}, {
									name : 'bz',
									mapping : 'bz'
								}, {
									name : 'maker',
									mapping : 'maker'
								}, {
									name : 'makeDate',
									mapping : 'makeDate'
								}, {
									name : 'type',
									mapping : 'type'
								}, {
									name : 'peifang',
									type : 'float',
									mapping : 'peifang'
								}, {
									name : 'spec_yz',
									mapping : 'spec_yz'
								}, {
									name : 'month1',
									mapping : 'month1'
								}, {
									name : 'year1',
									mapping : 'year1'
								}, {
									name : 'status',
									mapping : 'status'
								}])
			});

	ds.load({
				params : {
					start : 0
				},
				callback : function(records, o, s) {
					flag++;
					if (s) {
						form.getForm().loadRecord(ds.getAt(0));
						initTransnumDs();
						initSchemeDs();
					}
				}
			});

	ds.on("update", function(_this, _rec, _opt) {
		var A = ds.getAt(0).data["peifang"];
		var B = ds.getAt(0).data["qiandao_yield"];
		var C = ds.getAt(0).data["weimo"];
		var D = ds.getAt(0).data["yimo"];
		var E = ds.getAt(0).data["grossweight"];
		var F = ds.getAt(0).data["feipin"];
		var G = ds.getAt(0).data["qiandao_cost"];
		var H = ds.getAt(0).data["ordercost"];
		// alert(A+":"+B+":"+C+":"+D+":"+E+":"+F+":"+G);
		ds.getAt(0).data["product_cost_before"] = calcProductCostBefore(A, B,
				C, D, E, F, G);
		// alert(ds.getAt(0).data["product_cost_before"]);
		if (processDs.getCount() > 0 && _opt != "noloop") {
			// alert("noloop");
			processDs.fireEvent("update", processDs, processDs.getAt(0),
					"noloop");
		}
		ds.getAt(0).data["houdao_yield"] = calcHouDao(
				ds.getAt(0).data["specType"], processDs);
		if (processDs.getCount() != 0)
			ds.getAt(0).data["product_cost_last"] = calcProductCostLast(ds
							.getAt(0).data["baozhuangfei"], processDs
							.getAt(processDs.getCount() - 1).data["untilPrice"]);
		var I = ds.getAt(0).data["product_cost_last"];
		ds.getAt(0).data["lirun"] = calcLiRun(H, I);

		loadRecord();
		dsDirty = true;
	})
	initDs2();
	initProcessDs();
	initProcessDs2();
	initGrid1();
	initGrid2();
	initGrid();
	initMapDs();
	loadmask = getLoadMask();
	loadmask.show();
	runningFunction();
}
function calcProductCostBefore(A, B, C, D, E, F, G) {
	if (B == 0)
		B = 1;
	if (C == 0)
		C = 1;
	if (D == 0)
		D = 1;

	return tofloat((A + G) * E / B / C / D / (1 - F));
}
function calcHouDao(type, tempDs) {
	var result = 1;
	for (var i = 0; i < tempDs.getCount(); i++) {
		if (tempDs.getAt(i).data["processName"] == '前道磨加工'
				|| tempDs.getAt(i).data["processName"] == '芯子')
			continue;
		result *= tempDs.getAt(i).data["processYield"];
	}
	return tofloat(result);
}
function calcProductCostLast(A, B) {

	return tofloat((A + B) / 0.99);
}
function calcLiRun(A, B) {
	return tofloat((A - B) / A);
}
function calcAllUntilPrice(A, B, C, D) {

	if (!D)
		D = 1;
	processSaveStart = D;
	var before = A.getAt(0).data["product_cost_before"];
	if (C == 0)
		before = A.getAt(0).data["product_cost_before2"];
	if (D != 1)
		before = B.getAt(D - 2).data["untilPrice"];
	for (var i = D - 1; i < B.getCount(); i++) {
		if (B.getAt(i).data["processName"] == '芯子') {
			B.getAt(i).data["untilPrice"] = (before - B.getAt(i).data["processPrice"]
					* B.getAt(i).data["processYield"])
					+ B.getAt(i).data["otherFee"];
		} else {
			B.getAt(i).data["untilPrice"] = ((before / B.getAt(i).data["processNum"]) + B
					.getAt(i).data["processPrice"])
					/ B.getAt(i).data["processYield"]
					+ B.getAt(i).data["otherFee"];
		}
		B.getAt(i).data["untilPrice"] = tofloat(B.getAt(i).data["untilPrice"]);
		before = B.getAt(i).data["untilPrice"];

	}
}
function rotateSpec(A) {
	var arr = A.split('*');

	if (arr.length != 3)
		return [];
	else {
		var params = [];
		for (var i = 0; i < arr.length; i++) {
			if (/^\d*\.?\d*$/.test(arr[i])) {
				params.push(arr[i]);
			} else
				return [];
		}
		rotateSpecArr = [];
		var k = 0;
		for (var i = 0; i < params.length; i++) {

			rotateSpecArr.push([
					params[i] + "*" + params[(i + 1) % params.length] + "*"
							+ params[(i + 2) % params.length], k++]);
			rotateSpecArr.push([
					params[i] + "*" + params[(i + 2) % params.length] + "*"
							+ params[(i + 1) % params.length], k++]);
		}
		// alert(rotateSpecArr.length);
		return rotateSpecArr;
	}
}
function saveAllProcess(A, B) {
	if (!B)
		B = 1;
	A.each(function(rec) {
				if (rec.data["processPos"] >= B)
					orderSumSub.updateRecord(convert(rec), function(ret) {

							});
			});
}
function copyToDs2(A, B) {
	var C = A.getAt(0).data;
	var D = B.getAt(0).data;
	for (var property in C) {
		if (/(id)|(type)/.test(property))
			continue;
		D[property + '2'] = C[property];
	}
	B.fireEvent("update", B, B.getAt(0));
	Ext.Msg.alert("提示", "复制完成");
}
function copyToProcessDs2(A, B) {
	A.each(function(rec) {
				var num = B.find("processPos", rec.data["processPos"]);
				if (num < 0) {
					// alert("new");
					var newCopy = rec.copy();
					B.add(newCopy);
				} else {
					var BREC = B.getAt(num);

					BREC.data["processArea"] = rec.data["processArea"];
					BREC.data["processNum"] = rec.data["processNum"];
					BREC.data["unitPrice"] = rec.data["unitPrice"];
					BREC.data["processUpdate"] = rec.data["processUpdate"];
					BREC.data["processName"] = rec.data["processName"];
					BREC.data["processYield"] = rec.data["processYield"];
					BREC.data["afterSpec"] = rec.data["afterSpec"];
					BREC.data["processPrice"] = rec.data["processPrice"];
					BREC.data["otherFee"] = rec.data["otherFee"];
				}
			});
	B.fireEvent("update", B, B.getAt(0));
	Ext.Msg.alert("提示", "复制完成");
}
function initMapDs() {
	mapDs = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : '../processRelation.do?action=list'
						}),

				reader : new Ext.data.JsonReader({
							root : 'root'
						}, [{
									name : 'step'
								}, {
									name : 'workflow'
								}, {
									name : 'map'

								}, {
									name : 'pos',
									type : 'float'
								}])
			});
	mapDs.load({
				params : {
					start : 0
				}
			})
}
function initTransnumDs() {
	var rec = ds.getAt(0);
	orderSumMain.getFinishedList(rec.data["ssign"], rec.data["spec"],
			rec.data["plate"], Date.parseDate(rec.data["date1"], 'Y-m-d'),
			function(ret) {

				for (var i = 0; i < ret.length; i++) {
					transnumArr[i] = [ret[i].delvnum, ret[i].custid,
							ret[i].transnum];
				}
				transnumDs.loadData(transnumArr);

			});

}
function initSchemeDs() {
	var rec = ds.getAt(0);
	orderSumMain.getScheme(rec.data["spec"], function(ret) {

				var record = -1;
				var obj = {};
				// var schemeArr=[];
				for (var i = 0; i < ret.length; i++) {
					if (!obj[ret[i].scheme])
						obj[ret[i].scheme] = "";

					if (obj[ret[i].scheme] == "")
						obj[ret[i].scheme] += (ret[i].processName);
					else
						obj[ret[i].scheme] += ("-->" + ret[i].processName);

				}
				var k = 0;
				for (var prop in obj) {
					schemeArr[prop - 1] = [obj[prop], prop];
					// logger.debug("prop:"+prop+":"+schemeArr[prop-1]);
				}
				// obj=undefined;

				schemeDs.loadData(schemeArr);
				logger.debug(schemeDs.getCount());
				loadmask.hide();
			});
}
function initLikeSpecDs(workflow, map, spec) {
	loadmask.show();
	orderSumMain.getLikeSpec(workflow, map, spec, function(ret) {
				loadmask.hide();
				if (ret != null && ret.length > 0) {
					var tempArr = [];
					for (var i = 0; i < ret.length; i++) {
						tempArr.push([ret[i], i]);
					}

					procedureWin = getProcedureWin();
					procedureWin.setTitle("读取的相似规格列表");
					procedureDs.loadData(tempArr);
					procedureWin.show();
				} else
					Ext.Msg.alert("提示", "读取相似规格失败，可能没有存在对应的数据，请重新查询");
			});
}
function initMapArr() {
	var obj = {};
	var k = processDs.getCount();
	var pos = 3;
	for (var i = 0; i < k; i++) {
		// 从最后一行开始寻找

		var num = processDs.getAt(k - i - 1).data["processPos"] - 1;
		var name = processDs.getAt(k - i - 1).data["processName"];

		if (pos == 3) {
			mapArr.push(mapDs.findBy(function(rec) {
						if (rec.data["step"] == name && rec.data["pos"] == 3)
							return true;
						else
							return false;
					}));
			pos--;
		} else if (pos == 2) {
			if (name == '倒角' || name == '精加工') {
				mapArr.push(mapDs.findBy(function(rec) {
							if (rec.data["step"] == name
									&& rec.data["pos"] == 2)
								return true;
							else
								return false;
						}));
			} else {
				mapArr.push(mapDs.findBy(function(rec) {
							if (rec.data["step"] == name
									&& rec.data["pos"] == 2)
								return true;
							else
								return false;
						}));
				pos--;
			}
		} else {
			mapArr.push(mapDs.findBy(function(rec) {
						if (rec.data["step"] == name && rec.data["pos"] == 1)
							return true;
						else
							return false;
					}));
		}

	}

	mapArr.reverse();

}
function hideWin(tempWin) {
	var arr = tempWin.items.getRange();
	// alert("win.length:"+arr.length);
	for (var i = 0; i < arr.length; i++) {
		arr[i].hide();
	}

}
function closeWin(tempWin) {
	// 选择第一行的数据。
	// 或者选择默认的数据map

	if (tempWin.getId() == "map-win") {
		if (MAP != null)
			;
		else {
			var num = mapDs.find("step",
					runningSm.getSelections()[0].data["processName"])
			if (num > -1)
				MAP = mapDs.getAt(num).data["map"];
		}
	} else if (tempWin.getId() == "win1") {
		sm.selectFirstRow();
		winDefaultAction();
	}
	tempWin.hide();
}
var sm = new Ext.grid.CheckboxSelectionModel();
function showDataList(showDs, title) {

	if (!dataGrid)
		dataGrid = new Ext.grid.GridPanel({
					id : 'data-grid',
					ds : showDs,
					cm : cm,
					sm : sm,
					stripeRows : true,
					autoScroll : true,
					viewConfig : {
						forceFit : true
					},
					width : 400,
					autoHeight : true
				});
	else {
		dataGrid = null;
		// alert("dataGrid");
		dataGrid = new Ext.grid.GridPanel({
					id : 'data-grid',
					ds : showDs,
					cm : cm,
					sm : sm,
					width : 400,
					stripeRows : true,
					autoScroll : true,
					autoHeight : true,
					viewConfig : {
						forceFit : true
					}
				});
	}
	if (!dataForm)
		dataForm = new Ext.FormPanel({
					labelWidth : 95,
					method : 'post',
					frame : true,
					bodyStyle : 'padding:5px 5px 0',
					width : 400,
					height : 280,
					autoScroll : true,
					defaultType : 'textfield',
					standardSubmit : false,
					items : [dataGrid]
				});
	else {
		dataForm = null;
		dataForm = new Ext.FormPanel({
					labelWidth : 95,
					method : 'post',
					frame : true,
					bodyStyle : 'padding:5px 5px 0',
					width : 400,
					height : 280,
					autoScroll : true,
					defaultType : 'textfield',
					standardSubmit : false,
					items : [dataGrid]
				});
	}

	win = getWin();
	var items = new Ext.util.MixedCollection();
	items.add("dataForm", dataForm);
	win.items = items;
	hideWin(win);
	if (updateForm)
		updateForm.hide();
	dataForm.show();
	win.setTitle(title);
	win.show();
}
function winDefaultAction() {
	if (procedure == 0 && dataForm && dataForm.isVisible()) {// 开模规格的选取
		if (transnumError) {
			var sm = dataGrid.getSelectionModel();
			ds.getAt(0).data["transnum"] = sm.getSelections()[0].data["transnum"];
			// ds.fireEvent("update",ds,ds.getAt(0));
			procedure = 1;
		} else {
			var sm = dataGrid.getSelectionModel();
			ds.getAt(0).data["spec_yz"] = sm.getSelections()[0].data["spec"];
			ds.getAt(0).data["ssign_yz"] = sm.getSelections()[0].data["ssign"];
			ds.getAt(0).data["factory"] = sm.getSelections()[0].data["factory"];
			ds.fireEvent("update", ds, ds.getAt(0));
			selected = true;
			procedure = 2;
			sm.clearSelections();
		}
	}

	else if (procedure == -1) {
		// 进入导出excel处理
		var disList = [];
		var sm = dataGrid.getSelectionModel();
		var arr = sm.getSelections();
		for (var i = 0; i < arr.length; i++)
			disList.push(arr[i].data["tabId"]);

		orderExcel.setOkList(disList);
		orderExcel.print();
		procedure = 0;
	}

}
function getWin() {
	if (!win) {
		win = new Ext.Window({
					// el: 'add-window',
					// renderTo:'win1',
					id : 'win1',
					layout : 'fit',
					width : 400,
					height : 280,
					closeAction : 'hide',
					plain : true,
					items : dataForm,
					buttons : [{
								text : '保存',
								handler : function() {
									// 根据状态指示，添加到相应的数据里面。
									winDefaultAction();
									win.hide();

								}
							}, {
								text : '关闭',
								handler : function() {

									win.hide();
								}
							}]
				});
		win.on("hide", function(_this) {
					selected = false;
					processProcedure = 0;
					if (runningGrid)
						runningGrid.getView().refresh();
				});

	}
	return win;
}
function getMapWin() {
	if (!mapGrid) {
		var sm = new Ext.grid.CheckboxSelectionModel();
		mapGrid = new Ext.grid.GridPanel({
			id : 'map-grid',
			ds : mapDs,
			cm : new Ext.grid.ColumnModel([sm, {
						header : "加工名称",
						width : 80,
						dataIndex : 'step',
						editor : new fm.TextField({
									allowBlank : false
								})
					}, {
						header : "内部流程",
						width : 80,
						dataIndex : 'workflow',
						editor : new fm.TextField({
									allowBlank : false
								})
					}, {
						header : "读取的库表",
						width : 140,
						dataIndex : 'map',
						editor : new fm.TextField({
									allowBlank : false
								})
					}]),
			sm : sm,
			stripeRows : true,

			viewConfig : {
				forceFit : true
			},
			width : 300,
			height : 500,
			autoScroll : true
				// autoHeight : true
			});
	}
	if (!mapForm)
		mapForm = new Ext.FormPanel({
					labelWidth : 95,
					method : 'post',
					frame : true,
					bodyStyle : 'padding:5px 5px 0',
					width : 300,

					defaultType : 'textfield',
					standardSubmit : false,
					items : [mapGrid]
				});
	if (!mapWin) {
		mapWin = new Ext.Window({
					// el: 'add-window',
					// renderTo:'win1',
					title : '库表选取',
					id : 'map-win',
					layout : 'fit',
					width : 300,
					height : 400,
					closeAction : 'hide',
					plain : true,
					items : mapForm,
					buttons : [{
						text : '选取',
						handler : function() {
							var sm = mapGrid.getSelectionModel();
							if (sm.getCount() == 1) {

								var A = sm.getSelections()[0].data["workflow"];
								var B = sm.getSelections()[0].data["map"];
								if (procedureWinFlag == 4
										|| procedureWinFlag == -1) {
									Ext.Msg.prompt('输入规格', '该加工类型可能出现的字符(包含)',
											function(btn, text) {
												if (btn == 'ok') {
													var likeSpec = text;
													this.cache_search = likeSpec;
													initLikeSpecDs(A, B,
															likeSpec);

												}
											});
									mapWin.hide();

								} else {
									MAP = sm.getSelections()[0].data["map"];
									mapWin.hide();
								}

							} else {
								MAP = null;
								Ext.Msg.alert("錯誤", "請選擇一個數據");
							}
						}
					}, {
						text : '关闭',
						handler : function() {
							processProcedure = 0;
							// var sm = mapGrid.getSelectionModel();

							mapWin.hide();
						}
					}]
				});
		mapWin.on("hide", function(_this) {
					mapGrid.getSelectionModel().clearSelections();
				});

	}
	return mapWin;
}
function removeAllProcess() {

	dwr.engine.setAsync(false);
	// alert("removeAllProcess");
	processDs.each(function(rec) {
				// alert(rec.data["id"]);
				orderSumSub.removeRecord(rec.data["id"], function(ret) {
							if (!ret)
								Ext.Msg.alert("提示", "删除遇到错误。。。请联系管理员");
						})

			});

	processDs2.each(function(rec2) {
				// alert(rec2.data["id"]);
				orderSumSub.removeRecord(rec2.data["id"], function(ret) {
							if (!ret)
								Ext.Msg.alert("提示", "删除遇到错误。。。请联系管理员");
						})

			});

	processDs.removeAll();
	processDs2.removeAll();
	grid.getView().refresh();
	grid2.getView().refresh();

	dwr.engine.setAsync(true);
}
function getProcedureWin() {
	if (!procedureForm)
		procedureForm = new Ext.FormPanel({
			labelWidth : 80,
			method : 'post',
			frame : true,
			bodyStyle : 'padding:5px 5px 0',
			width : 400,

			defaultType : 'textfield',
			standardSubmit : false,
			items : [new Ext.form.ComboBox({
				fieldLabel : '选取数据',
				name : 'step',
				store : procedureDs,
				valueField : 'pos',
				displayField : 'step',
				typeAhead : true,
				mode : 'local',
				triggerAction : 'all',

				emptyText : '请选择...',
				selectOnFocus : true,
				forceSelection : true,
				width : 250,
				editable : true,
				listeners : {
					"select" : function(_this, _rec, _index) {
						procedureWin.hide();
						if (rotateStop) {
							if (procedureWinFlag == 0) {// first

								procedure = _rec.data["pos"];

							} else if (procedureWinFlag == 2) {

								processHopeProcedure = _rec.data["pos"];
							} else if (procedureWinFlag == 3) {

								Ext.Msg.confirm("提示",
										"是否需要将原来的加工细节数据先删除?'yes'--是，'no'--不是",
										function(button) {
											if (button == 'yes') {
												ds.getAt(0).data["processScheme"] = _rec.data["pos"];
												ds.fireEvent("update", ds, ds
																.getAt(0));
												removeAllProcess();
												runningMainDs = ds;
												procedure = 2;
											}

										})
							} else if (procedureWinFlag == 4) {
								Ext.Msg
										.confirm(
												"提示",
												"是否需要将该选择 '"
														+ _rec.data["step"]
														+ "' 的开模信息填充进订单?'yes'--是，'no'--不是",
												function(button) {
													if (button == 'yes') {

														var arr = _rec.data["step"]
																.split("\\");
														ds.getAt(0).data["spec_yz"] = arr[1]
																.split("_")[0];
														ds.getAt(0).data["ssign_yz"] = arr[0];
														ds
																.fireEvent(
																		"update",
																		ds,
																		ds
																				.getAt(0));
														// Ext.Msg.alert("提示","暂时无法对分厂号进行查找，请等待下个版本的更新。。谢谢配合");
														Ext.Msg
																.confirm(
																		"提示",
																		"是否需要根据开模规格来查找分厂号？",
																		function(
																				button) {
																			if (button == 'yes') {
																				orderSumMain
																						.getFactoryBySpec(
																								arr[0],
																								ds
																										.getAt(0).data["spec_yz"],
																								function(
																										ret) {
																									if (ret != null
																											&& ret.length > 0) {
																										var tempArr = [];
																										for (var i = 0; i < ret.length; i++) {
																											tempArr
																													.push([
																															ret[i],
																															i]);
																										}
																										procedureWinFlag = 5;
																										procedureWin = getProcedureWin();
																										procedureWin
																												.setTitle("读取分厂的列表");
																										procedureDs
																												.loadData(tempArr);
																										procedureWin
																												.show();
																									} else {
																										Ext.Msg
																												.alert(
																														"错误",
																														"没有找到对应的分厂列表,可能是数据库联接问题，请联系管理员");
																									}

																								});
																			}

																		});
													}

												});
							} else if (procedureWinFlag == 5) {
								var fac = _rec.data["step"].split("_")[0];
								Ext.Msg.confirm("提示", "是否将选择的这个分厂号" + fac
												+ "作为订单的生产号", function(button) {
											if (button == 'yes') {
												ds.getAt(0).data["factory"] = fac;
												ds.fireEvent("update", ds, ds
																.getAt(0));
											}
										});

							} else if (procedureWinFlag == 6) {
								var spec = _rec.data["step"].split("\\")[1];
								var process = getOSS();
								var num = process["processPos"];
								Ext.Msg.confirm("提示", "是否将选择的这个规格号" + spec
												+ "作为加工规格", function(button) {
											if (button == 'yes') {
												runningDs.getAt(num - 1).data["afterSpec"] = spec;
												runningDs
														.fireEvent(
																"update",
																runningDs,
																runningDs
																		.getAt(num
																				- 1),
																1);
												// form.find("name","peifang").setValue(ret);
												Ext.Msg
														.confirm(
																"提示:",
																"加工的规格为："
																		+ spec
																		+ ",'yes'--继续','no'--退出自动'",
																function(button) {
																	if (button == "yes") {
																		processProcedure = 2;// 先退出
																	} else
																		processProcedure = 0;
																	if (mapWin)
																		mapWin
																				.hide();
																})
											}
										});

							} else if (procedureWinFlag == -1) {
								Ext.Msg
										.confirm(
												"提示",
												"是否需要将该选择 '"
														+ _rec.data["step"]
														+ "' 的规格信息作为加工规格?'yes'--是，'no'--不是",
												function(button) {
													if (button == 'yes') {
														var arr = _rec.data["step"]
																.split("\\");
														var spec = arr[1]
																.split("_")[0];
														var sm = runningGrid
																.getSelectionModel();

														sm.getSelections()[0].data["afterSpec"] = spec;
														runningDs
																.fireEvent(
																		"update",
																		runningDs,
																		sm
																				.getSelections()[0]);
														processProcedure = 2;
													}

												});

							} else {

								processAction();
								processProcedure = _rec.data["pos"];
							}
						} else {

							rotateValue = _rec.data["step"];

							// alert(rotateValue);
							processProcedure = 2;
						}

					}
				}
			})]
		});
	if (!procedureWin) {
		procedureWin = new Ext.Window({
					// el: 'add-window',
					// renderTo:'win1',
					id : 'procedure-win',
					title : '结算步骤的选取',
					layout : 'fit',
					width : 450,
					height : 100,
					closeAction : 'hide',
					plain : true,
					items : procedureForm
				});
		procedureWin.on("hide", function(_this) {
					// mapGrid.getSelectionModel().clearSelections();
					procedureForm.getForm().reset();
					procedureForm.find("name", "step")[0].setValue("");
				});

	}
	// procedureWin.expand();
	return procedureWin;
}
function getOSM() {
	return convert(runningMainDs.getAt(0));
}
function getOSS() {
	return convert(runningSm.getSelections()[0]);
}
function readKaiMo() {
	if (procedure == 1) {
		procedure = 0;

		var osm = getOSM();
		loadmask.show();
		orderSumMain.readKaiMo(osm, function(ret) {
					loadmask.hide();
					if (ret != null && ret.length > 0) {
						cm = null;
						var sm = new Ext.grid.CheckboxSelectionModel();
						cm = new Ext.grid.ColumnModel([sm, {
									header : "入库牌号",
									width : 100,
									sortable : true,
									dataIndex : 'ssign'
								}, {
									header : "入库规格",
									width : 150,
									sortable : true,
									dataIndex : 'spec'
								}, {
									header : "分厂",
									width : 100,
									sortable : true,
									dataIndex : 'factory'
								}]);
						var list = [];
						for (var i = 0; i < ret.length; i++) {
							var arr = ret[i].split("_");
							var arr2 = arr[1].split("\\");
							list[i] = [arr2[0].substring(1), arr2[1], arr[0]];
						}
						showDs = new Ext.data.SimpleStore({
									fields : ['ssign', 'spec', 'factory'],
									data : list
								});

						showDataList(showDs, "开模信息选取");
						transnumError = false;
					} else {
						Ext.Msg.confirm("错误",
								"暂时未能找到对应订单号的开模规格，是否需要重新设置订单号来查找规格", function(
										button) {
									if (button == 'yes') {
										transnumError = true;
										cm = null;

										var sm = new Ext.grid.CheckboxSelectionModel();
										cm = new Ext.grid.ColumnModel([sm, {
													header : "发货编号",
													// width : 50,
													sortable : true,
													dataIndex : 'delvnum'
												}, {
													header : "客户编号",
													// width : 50,
													sortable : true,
													dataIndex : 'custid'
												}, {
													header : "订单编号",
													// width : 50,
													sortable : true,
													dataIndex : 'transnum'
												}]);

										showDs = transnumDs;

										showDataList(showDs, "重新选取发货订单");
									}

								});
					}
					procedure = 0;
				});
	}

}
function createOSS() {
	// alert(procedure);
	if (procedure == 2) {
		procedure = 0;

		var osm = getOSM();
		Ext.Msg.confirm("提示", "是否需要真正创建对应的加工细节？'yes'--是，'no'--不需要", function(
				button) {
			// alert(button);
			if (button == 'yes') {
				// alert(osm["processScheme"]);
				loadmask.show();
				orderSumMain.createOSS(osm, function(ret) {
					loadmask.hide();
					if (ret) {
						procedure = 3;
						processDs.load({
									params : {

										test : 11
									},

									callback : function(records, o, s) {
										if (s) {
											grid.getView().refresh();
										}
									}
								});

						Ext.Msg.alert("提示", "目前已经完成加工基本细节的创建");

					} else {

						Ext.Msg.confirm("提示:",
								"遇到错误，可能该加工细节已经创建，是否保留加工细节，跳过这个阶段？", function(
										button) {
									if (button == "yes") {
										flag = 4;
										procedure = 3;
									} else {
										Ext.Msg
												.confirm(
														"提示,",
														"是否需要将该加工细节先删除?'yes'--是,'no'--不是",
														function(button) {
															if (button == 'yes') {
																removeAllProcess();
																procedure = 2;
															}

														})
										procedure = 0;
									}
								});
					}
				});
			} else
				;// alert("no create");
		});

	}
}
function getPeiFang() {
	if (procedure == 3) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		peifang.getPeiFang(osm["factory"], osm["ssign_yz"], osm["month1"],
				osm["year1"], function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["peifang"] = ret;
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "配方价格为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 4;
								})
					} else {

						Ext.Msg.confirm("错误,",
								"没有找到对应的配方价格，请联系管理员添加,是否需要暂时跳过，继续进行下一步？",
								function(button) {
									if (button == 'yes') {
										procedure = 4;
									} else {
										procedure = 0;
									}

								});
					}
				});
	}
}
function getWeiMo() {
	if (procedure == 4) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		processRelation.getRelationYield("未磨", osm["ssign_yz"], osm["spec_yz"],
				osm["plate"], osm["month1"], osm["year1"], osm["factory"],
				function(ret) {
					loadmask.hide();
					if (ret) {
						ds.getAt(0).data["weimo"] = ret;
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "未磨成品率为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 5;
								})
					} else {
						Ext.Msg.confirm("提示", "找不到" + osm["year1"] + "年"
										+ osm["month1"]
										+ "月的未磨成品率,是否需要自动搜索前面某个月的未磨成品率?",
								function(button) {

									if (button == "yes") {
										loadmask.show();
										processRelation.getAutoRelationYield(
												"未磨", osm["ssign_yz"],
												osm["spec_yz"], osm["plate"],
												osm["month1"], osm["year1"],
												osm["factory"], function(ret) {
													loadmask.hide();
													if (!ret)
														ret = "";
													var arr = ret.split("_");
													if (ret.length == 3
															&& arr[2] != 0) {

														var _year1 = arr[0];
														var _month1 = arr[1];
														var _yield = arr[2];
														ds.getAt(0).data["weimo"] = _yield;
														ds.fireEvent("update");
														Ext.Msg
																.confirm(
																		"提示:",
																		_year1
																				+ "年"
																				+ _month1
																				+ "月未磨成品率为"
																				+ _yield
																				+ ",'yes'--继续','no'--退出自动'",
																		function(
																				button) {
																			if (button == "no") {
																				procedure = 0;// 先退出
																			} else
																				procedure = 5;
																		})
													} else
														Ext.Msg
																.confirm(
																		"提示",
																		"找不到实际的成品率，是否需要用默认的未磨成品率进行替代？'yes'--是，'no'--不需要",
																		function(
																				button) {
																			if (button == 'yes') {
																				otherConstants
																						.getOtherConstants(
																								"未磨默认成品率",
																								osm["specType"],
																								function(
																										ret) {
																									if (ret) {
																										ds
																												.getAt(0).data["weimo"] = ret;
																										ds
																												.fireEvent(
																														"update",
																														ds,
																														ds
																																.getAt(0));
																										Ext.Msg
																												.confirm(
																														"提示",
																														"未磨默认成品率为:"
																																+ ret
																																+ ",'yes'--继续,'no'--退出",
																														function(
																																button) {
																															if (button == 'yes')
																																procedure = 5;
																															else
																																procedure = 0;
																														});
																									} else {
																										Ext.Msg
																												.alert(
																														"错误",
																														"没有找到未磨默认成品率,请联系管理员设置");
																										procedure = 0;
																									}
																								});
																			} else
																				procedure = 0;
																		});
												});
									} else {
										Ext.Msg
												.confirm(
														"提示",
														"找不到实际的成品率，是否需要用默认的未磨成品率进行替代？'yes'--是，'no'--不需要",
														function(button) {
															if (button == 'yes') {
																otherConstants
																		.getOtherConstants(
																				"未磨默认成品率",
																				osm["specType"],
																				function(
																						ret) {
																					if (ret) {
																						ds
																								.getAt(0).data["weimo"] = ret;
																						ds
																								.fireEvent(
																										"update",
																										ds,
																										ds
																												.getAt(0));
																						Ext.Msg
																								.confirm(
																										"提示",
																										"未磨默认成品率为:"
																												+ ret
																												+ ",'yes'--继续,'no'--退出",
																										function(
																												button) {
																											if (button == 'yes')
																												procedure = 5;
																											else
																												procedure = 0;
																										});
																					} else {
																						Ext.Msg
																								.alert(
																										"错误",
																										"没有找到未磨默认成品率,请联系管理员设置");
																						procedure = 0;
																					}
																				});
															} else
																procedure = 0;
														});
									}
								});

					}
				});
	}
}
function getYiMo() {
	if (procedure == 5) {
		procedure = 0;
		var osm = getOSM();
		var num = processDs.find("processName", "前道磨加工");
		logger.debug(" found mo jiagong:" + num);
		if ((osm["specType"] != "yuanzhu" && osm["specType"] != 'taokong')
				|| num > -1) {
			Ext.Msg.confirm("提示", "由于已磨变成了后面的前道磨加工，所以该道的成品率为1,是否继续？", function(
							button) {
						if (button == 'yes') {
							procedure = 6;
						}

					})
			return;
		}
		loadmask.show();
		processRelation.getRelationYield("已磨", osm["ssign_yz"], osm["spec_yz"],
				osm["plate"], osm["month1"], osm["year1"], osm["factory"],
				function(ret) {
					loadmask.hide();
					if (ret) {
						ds.getAt(0).data["yimo"] = ret;
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "已磨成品率为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 6;
								})
					} else {

						Ext.Msg.confirm("提示", "找不到" + osm["year1"] + "年"
										+ osm["month1"]
										+ "月的已磨成品率,是否需要自动搜索前面某个月的已磨成品率?",
								function(button) {

									if (button == "yes") {
										loadmask.show();
										processRelation.getAutoRelationYield(
												"已磨", osm["ssign_yz"],
												osm["spec_yz"], osm["plate"],
												osm["month1"], osm["year1"],
												osm["factory"], function(ret) {
													loadmask.hide();
													if (!ret)
														ret = "";
													var arr = ret.split("_");
													if (ret.length == 3
															&& arr[2] != 0) {

														var _year1 = arr[0];
														var _month1 = arr[1];
														var _yield = arr[2];
														ds.getAt(0).data["yimo"] = _yield;
														ds.fireEvent("update");
														Ext.Msg
																.confirm(
																		"提示:",
																		_year1
																				+ "年"
																				+ _month1
																				+ "月已磨成品率为"
																				+ _yield
																				+ ",'yes'--继续','no'--退出自动'",
																		function(
																				button) {
																			if (button == "no") {
																				procedure = 0;// 先退出
																			} else
																				procedure = 6;
																		})
													} else
														Ext.Msg
																.confirm(
																		"提示",
																		"找不到实际的成品率，是否需要用默认的已磨成品率进行替代？'yes'--是，'no'--不需要",
																		function(
																				button) {
																			if (button == 'yes') {
																				otherConstants
																						.getOtherConstants(
																								"已磨默认成品率",
																								osm["specType"],
																								function(
																										ret) {
																									if (ret) {
																										ds
																												.getAt(0).data["yimo"] = ret;
																										ds
																												.fireEvent(
																														"update",
																														ds,
																														ds
																																.getAt(0));
																										Ext.Msg
																												.confirm(
																														"提示",
																														"已磨默认成品率为:"
																																+ ret
																																+ ",'yes'--继续,'no'--退出",
																														function(
																																button) {
																															if (button == 'yes')
																																procedure = 6;
																															else
																																procedure = 0;
																														});
																									} else {
																										Ext.Msg
																												.alert(
																														"错误",
																														"没有找到已磨默认成品率,请联系管理员设置");
																										procedure = 0;
																									}
																								});
																			} else
																				procedure = 0;
																		});
												});
									} else {
										Ext.Msg
												.confirm(
														"提示",
														"找不到实际的成品率，是否需要用默认的已磨成品率进行替代？'yes'--是，'no'--不需要",
														function(button) {
															if (button == 'yes') {
																otherConstants
																		.getOtherConstants(
																				"已磨默认成品率",
																				osm["specType"],
																				function(
																						ret) {
																					if (ret) {
																						ds
																								.getAt(0).data["yimo"] = ret;
																						ds
																								.fireEvent(
																										"update",
																										ds,
																										ds
																												.getAt(0));
																						Ext.Msg
																								.confirm(
																										"提示",
																										"已磨默认成品率为:"
																												+ ret
																												+ ",'yes'--继续,'no'--退出",
																										function(
																												button) {
																											if (button == 'yes')
																												procedure = 6;
																											else
																												procedure = 0;
																										});
																					} else {
																						Ext.Msg
																								.alert(
																										"错误",
																										"没有找到已磨默认成品率,请联系管理员设置");
																						procedure = 0;
																					}
																				});
															} else
																procedure = 0;
														});
									}
								});
					}
				});
	}
}
function getGrossWeight() {
	if (procedure == 6) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		processRelation.getRelationYield("毛重", osm["ssign_yz"], osm["spec_yz"],
				osm["plate"], osm["month1"], osm["year1"], osm["factory"],
				function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["grossweight"] = ret;
						ds.fireEvent("update");
						Ext.Msg.confirm("提示:", "实际毛重为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 7;
								})
					} else {
						Ext.Msg.confirm("提示", "找不到" + osm["year1"] + "年"
										+ osm["month1"]
										+ "月的毛重,是否需要自动搜索前面某个月的毛重?", function(
										button) {

									if (button == "yes") {
										loadmask.show();
										processRelation.getAutoRelationYield(
												"毛重", osm["ssign_yz"],
												osm["spec_yz"], osm["plate"],
												osm["month1"], osm["year1"],
												osm["factory"], function(ret) {
													loadmask.hide();
													if (!ret)
														ret = "";
													var arr = ret.split("_");
													if (ret.length == 3
															&& arr[2] != 0) {

														var _year1 = arr[0];
														var _month1 = arr[1];
														var _yield = arr[2];
														ds.getAt(0).data["grossweight"] = _yield;
														ds.fireEvent("update");
														Ext.Msg
																.confirm(
																		"提示:",
																		_year1
																				+ "年"
																				+ _month1
																				+ "月毛重为"
																				+ _yield
																				+ ",'yes'--继续','no'--退出自动'",
																		function(
																				button) {
																			if (button == "no") {
																				procedure = 0;// 先退出
																			} else
																				procedure = 7;
																		})
													} else
														Ext.Msg
																.confirm(
																		"提示",
																		"找不到实际的毛重，是否采用理论毛重替换,'yes'--是,'no'--不需要",
																		function(
																				button) {
																			if (button == 'yes') {
																				orderSumSub
																						.getHopeGrossWeight(
																								osm["ssign_yz"],
																								osm["spec_yz"],
																								function(
																										ret) {
																									if (ret) {
																										ds
																												.getAt(0).data["grossweight"] = ret;
																										ds
																												.fireEvent(
																														"update",
																														ds,
																														ds
																																.getAt(0));
																										Ext.Msg
																												.confirm(
																														"提示",
																														"理论毛重为:"
																																+ ret
																																+ ",'yes'--继续,'no'--退出",
																														function(
																																button) {
																															if (button == 'yes')
																																procedure = 7;
																															else
																																procedure = 0;
																														});
																									} else {
																										Ext.Msg
																												.alert(
																														"错误",
																														"没有找到理论毛重,请联系管理员设置");
																										procedure = 0;
																									}
																								});
																			} else
																				procedure = 0;

																		});
												});
									} else {
										Ext.Msg
												.confirm(
														"提示",
														"找不到实际的毛重，是否采用理论毛重替换,'yes'--是,'no'--不需要",
														function(button) {
															if (button == 'yes') {
																orderSumSub
																		.getHopeGrossWeight(
																				osm["ssign_yz"],
																				osm["spec_yz"],
																				function(
																						ret) {
																					if (ret) {
																						ds
																								.getAt(0).data["grossweight"] = ret;
																						ds
																								.fireEvent(
																										"update",
																										ds,
																										ds
																												.getAt(0));
																						Ext.Msg
																								.confirm(
																										"提示",
																										"理论毛重为:"
																												+ ret
																												+ ",'yes'--继续,'no'--退出",
																										function(
																												button) {
																											if (button == 'yes')
																												procedure = 7;
																											else
																												procedure = 0;
																										});
																					} else {
																						Ext.Msg
																								.alert(
																										"错误",
																										"没有找到理论毛重,请联系管理员设置");
																						procedure = 0;
																					}
																				});
															} else
																procedure = 0;

														});
									}
								});
					}
				});
	}
}
function getQianDaoYield() {
	if (procedure == 7) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		qianDaoYield.getQianDaoYield(osm["factory"], osm["ssign_yz"],
				osm["month1"], osm["year1"], function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["qiandao_yield"] = ret;
						ds.fireEvent("update");
						if (ret == 1) {
							Ext.Msg.alert("提示", "可能前道收得率没有设置~");
						}
						Ext.Msg.confirm("提示:", "前道收得率为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 8;
								})
					} else
						procedure = 0;
				});
	}
}
function getFeiPin() {
	if (procedure == 8) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		otherConstants.getOtherConstants("废品率", "", function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["feipin"] = ret;
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "废品率为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 9;
								})
					} else
						procedure = 0;
				});
	}
}
function getQianDaoFee() {
	if (procedure == 9) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		otherConstants.getQianDaoFee(osm["spec_yz"], osm["grossweight"],
				function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["qiandao_cost"] = ret;
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "前道费用为" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										procedure = 0;// 先退出
									} else
										procedure = 10;
								})
					} else {
						Ext.Msg.alert("错误", "前道费用为0，可能是没有设置前道费用，请自己手动添加");
						procedure = 0;
					}
				});
	}
}
function getBaoZhuangFee() {
	if (procedure == 10) {
		procedure = 0;
		var osm = getOSM();
		loadmask.show();
		otherConstants.getBaoZhuangFei(osm["spec"], osm["ssign"],
				function(ret) {
					loadmask.hide();
					if (ret) {

						ds.getAt(0).data["baozhuangfei"] = tofloat(ret);
						ds.fireEvent("update");
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "包装费为"
										+ ds.getAt(0).data["baozhuangfei"]
										+ ",是否需要退出自动，手工设定？", function(button) {
									if (button == "yes") {
										procedure = 0;// 先退出
									} else
										procedure = 11;
								})
					} else {
						Ext.Msg.confirm("提示：",
								"读取包装费遇到错误，可能是密度牌号未设定，'yes'-退出设定，'no'-继续进行",
								function(button) {
									if (button == 'yes') {
										procedure = 0;
									} else
										procedure = 12;

								});

					}
				});
	}
}
function getProcessSpec() {
	if (processProcedure == 1) {
		/*
		 * if (!MAP) {
		 * 
		 * mapWin = getMapWin(); if (mapWin.isVisible()) return; mapWin.show();
		 * window.setTimeout("closeWin(mapWin)", 20 * WAITTIME); return; }
		 */
		// 暂时先注销掉，不让其选择表，选择它出现
		if (mapArr.length < 1) {
			initMapArr();
		}
		// TODO 需要增加第一个规格选定了以后，其它规格可以提示是否需要确定。
		processProcedure = 0;
		var osm = getOSM();
		var process = getOSS();
		var num = process["processPos"];
		var allRec = mapDs.getAt(mapArr[process["processPos"] - 1]);
		// alert(mapArr[process["processPos"] - 1]);
		MAP = allRec.data["map"];
		// alert(MAP);
		if (allRec.data["pos"] == 2) {
			processProcedure = 2;
			return;
		}
		loadmask.show();
		if (process["processName"] == "芯子") {
			orderSumSub.getXinZiSpec(osm["spec_yz"], osm["spec"],
					function(ret) {
						loadmask.hide();
						if (ret && ret != "") {
							Ext.Msg.confirm("提示", "是否将该规格" + ret + "作为芯子的规格",
									function(button) {
										if (button == 'yes') {
											runningDs.getAt(num - 1).data["afterSpec"] = ret;
											runningDs.fireEvent("update",
													runningDs, runningDs
															.getAt(num - 1), 1);
											processProcedure = 2;// 先退出
										} else {
											processProcedure = 0;
										}
									});
						} else
							Ext.Msg.alert("错误", "芯子的规格无法计算得出，请联系管理员设置芯子尺寸");
					});
		} else if (process["processName"] == "倒角"
				|| process["processName"] == "电镀") {// 倒角和电镀的加工规格不需要去动。

			processProcedure = 2;
			return;
		} else {
			var before;
			if (num == 1)
				before = osm["spec_yz"];
			else {
				if (runningDs.getAt(num - 2).data["processName"] == '芯子')
					before = runningDs.getAt(num - 3).data["afterSpec"];
				else
					before = runningDs.getAt(num - 2).data["afterSpec"];
			}
			var temp = helper.getNextSpec(before, process["processName"],
					osm["spec"]);
			if (temp) {
				Ext.Msg.confirm("提示", "根据前面规格，计算得到的规格是：" + temp + ",是否接受?",
						function(button) {
							if (button == 'yes') {
								loadmask.hide();
							
								runningDs.getAt(num - 1).data["afterSpec"] = temp;
											
								runningDs.fireEvent("update", runningDs,runningDs.getAt(num - 1), 1);
								processProcedure = 2; // 先退出
							} else {
								orderSumSub.getProcessSpec(osm["transnum"],
										process["processName"], MAP, function(
												ret) {
											loadmask.hide();
											if (ret != null && ret.length > 0) {
												var tempArr = [];
												for (var i = 0; i < ret.length; i++) {
													tempArr.push([ret[i], i]);
												}
												procedureWinFlag = 6;
												procedureWin = getProcedureWin();
												procedureWin
														.setTitle("读取的加工规格列表");
												procedureDs.loadData(tempArr);
												procedureWin.show();
											} else {
												Ext.Msg
														.confirm(
																"提示",
																"找不到对应的加工规格，是否需要查找其他类似的规格？'yes'--是，'no'--不需要，退出",
																function(button) {
																	if (button == 'yes') {
																		procedureWinFlag = -1;
																		var A = allRec.data["workflow"];
																		var B = allRec.data["map"];

																		Ext.Msg
																				.prompt(
																						'输入规格',
																						'该加工类型可能出现的字符(包含)',
																						function(
																								btn,
																								text) {
																							if (btn == 'ok') {
																								var likeSpec = text;

																								initLikeSpecDs(
																										A,
																										B,
																										likeSpec);

																							}
																						});

																	} else {

																		if (num == 1)
																			runningDs
																					.getAt(num
																							- 1).data["afterSpec"] = osm["spec_yz"];
																		else
																			runningDs
																					.getAt(num
																							- 1).data["afterSpec"] = runningDs
																					.getAt(num
																							- 2).data["afterSpec"];
																		runningDs
																				.fireEvent(
																						"update",
																						runningDs,
																						runningDs
																								.getAt(num
																										- 1),
																						1);
																		processProcedure = 0;// 先退出
																	}
																});
											}

										});
							}
						});
			} else {
				orderSumSub.getProcessSpec(osm["transnum"],
						process["processName"], MAP, function(ret) {
							loadmask.hide();
							if (ret != null && ret.length > 0) {
								var tempArr = [];
								for (var i = 0; i < ret.length; i++) {
									tempArr.push([ret[i], i]);
								}
								procedureWinFlag = 6;
								procedureWin = getProcedureWin();
								procedureWin.setTitle("读取的加工规格列表");
								procedureDs.loadData(tempArr);
								procedureWin.show();
							} else {
								Ext.Msg
										.confirm(
												"提示",
												"找不到对应的加工规格，是否需要查找其他类似的规格？'yes'--是，'no'--不需要，退出",
												function(button) {
													if (button == 'yes') {
														procedureWinFlag = -1;
														var A = allRec.data["workflow"];
														var B = allRec.data["map"];

														Ext.Msg
																.prompt(
																		'输入规格',
																		'该加工类型可能出现的字符(包含)',
																		function(
																				btn,
																				text) {
																			if (btn == 'ok') {
																				var likeSpec = text;

																				initLikeSpecDs(
																						A,
																						B,
																						likeSpec);

																			}
																		});

													} else {

														if (num == 1)
															runningDs.getAt(num
																	- 1).data["afterSpec"] = osm["spec_yz"];
														else
															runningDs.getAt(num
																	- 1).data["afterSpec"] = runningDs
																	.getAt(num
																			- 2).data["afterSpec"];
														runningDs
																.fireEvent(
																		"update",
																		runningDs,
																		runningDs
																				.getAt(num
																						- 1),
																		1);
														processProcedure = 0;// 先退出
													}
												});
							}

						});
			}

		}
	}
}
function getProcessArea() {
	if (processProcedure == 2) {
		processProcedure = 0;
		var osm = getOSM();
		var process = getOSS();
		var before;
		var num = process["processPos"];
		if (num == 1)
			before = osm["spec_yz"];
		else {
			if (runningDs.getAt(num - 2).data["processName"] == '芯子')
				before = runningDs.getAt(num - 3).data["afterSpec"];
			else
				before = runningDs.getAt(num - 2).data["afterSpec"];
		}
		rotateStop = false;

		if (!rotateStop) {
			// before = rotateValue;
			var after = process["afterSpec"];
			var str = "";
			if (process["processName"] == '前道磨加工') {
				after = osm["spec"];
			}
			loadmask.show();
			orderSumSub.getProcessArea(before, after, process["processName"],
					function(ret) {
						loadmask.hide();
						if (ret) {
							var volume = ret;
							// form.find("name","peifang").setValue(ret);
							if (process["processName"] == "芯子") {
								orderSumSub.getDensity(osm["ssign_yz"],
										function(ret) {
											if (ret) {
												runningDs.getAt(num - 1).data["processArea"] = tofloat(volume
														* ret);
												runningDs
														.fireEvent(
																"update",
																runningDs,
																runningDs
																		.getAt(num
																				- 1),
																2);

											} else {
												Ext.Msg.alert("错误",
														"请联系管理员，设置密度牌号对应关系");
											}
										});
							} else {
								runningDs.getAt(num - 1).data["processArea"] = volume;
								runningDs.fireEvent("update", runningDs,
										runningDs.getAt(num - 1), 2);
							}
							Ext.Msg
									.confirm(
											"提示:",
											"加工的面积为："
													+ runningDs.getAt(num - 1).data["processArea"]
													+ ",'yes'--继续','no'--退出自动'",
											function(button) {
												if (button == "no") {
													processProcedure = 0;// 先退出
												} else
													processProcedure = 3;
											})

						} else {
							processProcedure = 0;
							Ext.Msg
									.confirm(
											"错误",
											"可能由于面积公式的设置有问题，也可能是该加工步骤可能是不需要的(倒角，磨加工等),'yes'--是，继续，'no'--退出",
											function(button) {
												if (button == 'yes') {
													processProcedure = 3;
												}
											});

						}
					});
			rotateStop = true;
		}
	}
}
function getProcessFee() {
	if (processProcedure == 3) {
		processProcedure = 0;
		var osm = getOSM();
		var process = getOSS();
		var before;
		var num = process["processPos"];
		if (num == 1)
			before = osm["spec_yz"];
		else {
			if (runningDs.getAt(num - 2).data["processName"] == '芯子')
				before = runningDs.getAt(num - 3).data["afterSpec"];
			else
				before = runningDs.getAt(num - 2).data["afterSpec"];
		}
		if (process["processName"] == "电镀") {
			loadmask.show();
			orderSumSub.getDianDuFee(osm["plate"], function(ret) {
						loadmask.hide();
						if (ret) {
							runningDs.getAt(num - 1).data["unitPrice"] = ret;
							runningDs.fireEvent("update", runningDs, runningDs
											.getAt(num - 1), 3);
							// form.find("name","peifang").setValue(ret);

							Ext.Msg.confirm("提示:", "加工的费用为：" + ret
											+ ",'yes'--继续','no'--退出自动'",
									function(button) {
										if (button == "no") {
											processProcedure = 0;// 先退出
										} else
											processProcedure = 4;
									});
						} else {
							Ext.Msg.alert("提示:", "暂时无法找到对应的电镀材料的价格,请重新设置");
							processProcedure = 0;
						}
					})
		} else if (process["processName"] == "芯子") {
			Ext.Msg.confirm("提示:", "芯子的加工单价为入库成本(" + osm["peifang"] + ")+前道费用("
							+ osm["qiandao_cost"] + "),是--同意，否--手工输入数据",
					function(button) {
						if (button == 'yes') {
							runningDs.getAt(num - 1).data["unitPrice"] = tofloat(osm["peifang"]
									+ osm["qiandao_cost"]);
							runningDs.fireEvent("update", runningDs, runningDs
											.getAt(num - 1), 3);
							// form.find("name","peifang").setValue(ret);

							Ext.Msg
									.confirm(
											"提示:",
											"加工的费用为："
													+ runningDs.getAt(num - 1).data["unitPrice"]
													+ ",'yes'--继续','no'--退出自动'",
											function(button) {
												if (button == "no") {
													processProcedure = 0;// 先退出
												} else
													processProcedure = 4;
											});
						} else {

						}
					});
		} else {
			loadmask.show();
			orderSumSub.getProcessFee(before, process["afterSpec"],

					process["processName"], function(ret) {
						loadmask.hide();
						if (ret) {
							if (ret > MAXFEE) {
								Ext.Msg
										.confirm(
												"提示:",
												"加工费:"
														+ ret
														+ " 的价格过大，可能是整个加工费的价格,是否需要除以加工面积，便于结算？",
												function(button) {
													if (button == 'yes') {
														runningDs
																.getAt(num - 1).data["unitPrice"] = tofloat(ret
																/ runningDs
																		.getAt(num
																				- 1).data["processArea"]);
														runningDs
																.fireEvent(
																		"update",
																		runningDs,
																		runningDs
																				.getAt(num
																						- 1),
																		3);
														// form.find("name","peifang").setValue(ret);
														Ext.Msg
																.confirm(
																		"提示:",
																		"加工的费用为："
																				+ ret
																				+ ",'yes'--继续','no'--退出自动'",
																		function(
																				button) {
																			if (button == "no") {
																				processProcedure = 0;// 先退出
																			} else
																				processProcedure = 4;
																		});
													} else {
														runningDs
																.getAt(num - 1).data["unitPrice"] = ret;
														runningDs
																.fireEvent(
																		"update",
																		runningDs,
																		runningDs
																				.getAt(num
																						- 1),
																		3);
														Ext.Msg
																.confirm(
																		"提示:",
																		"加工的费用为："
																				+ ret
																				+ ",'yes'--继续','no'--退出自动'",
																		function(
																				button) {
																			if (button == "no") {
																				processProcedure = 0;// 先退出
																			} else
																				processProcedure = 4;
																		});
													}

												})
							} else {
								runningDs.getAt(num - 1).data["unitPrice"] = ret;
								runningDs.fireEvent("update", runningDs,
										runningDs.getAt(num - 1), 3);
								// form.find("name","peifang").setValue(ret);
								Ext.Msg.confirm("提示:", "加工的费用为：" + ret
												+ ",'yes'--继续','no'--退出自动'",
										function(button) {
											if (button == "no") {
												processProcedure = 0;// 先退出
											} else
												processProcedure = 4;
										});
							}

						} else {
							Ext.Msg.alert("错误", "请联系管理员，设置下加工费用~");
							processProcedure = 0;
						}
					});
		}
	}
}
function getProcessYield() {
	if (processProcedure == 4) {
		var osm = getOSM();
		// alert(osm["type"]);
		/*
		 * if (!MAP && osm["type"] == 1) {
		 * 
		 * mapWin = getMapWin(); if (mapWin.isVisible()) return; mapWin.show();
		 * window.setTimeout("closeWin(mapWin)", 20 * WAITTIME); return; }
		 */
		if (mapArr.length < 1) {
			initMapArr();
		}
		processProcedure = 0;

		var process = getOSS();
		var before;
		var num = process["processPos"];
		if (num == 1)
			before = osm["spec_yz"];
		else
			before = runningDs.getAt(num - 2).data["afterSpec"];
		var allRec = mapDs.getAt(mapArr[process["processPos"] - 1]);
		MAP = allRec.data["map"];
		YIMO_MJG = false;
		if (process["processName"] == '倒角') {// 倒角的话，直接跳过加工成品率这项。
			processProcedure = 5;
			return;
		}

		var ssign = osm["ssign"];
		if (process["processName"] == '前道磨加工')
			ssign = osm["ssign_yz"];
			
		if(osm["type"]==0)
			Ext.Msg.alert("错误","请尽量用目标成品率按钮里面的替换默认加工成品率，不然默认成品率可能不对");
		loadmask.show();
		
		orderSumSub.getProcessYield(process["processName"], MAP, ssign,
				process["afterSpec"], osm["plate"], osm["month1"],
				osm["year1"], osm["factory"], osm["type"], function(ret) {
					loadmask.hide();
					if (ret) {
						runningDs.getAt(num - 1).data["processYield"] = ret;
						runningDs.fireEvent("update", runningDs, runningDs
										.getAt(num - 1), 4);
						// form.find("name","peifang").setValue(ret);
						Ext.Msg.confirm("提示:", "加工成品率为：" + ret
										+ ",'yes'--继续','no'--退出自动'", function(
										button) {
									if (button == "no") {
										processProcedure = 0;// 先退出
									} else
										processProcedure = 5;
								})
					} else {

						Ext.Msg
								.confirm(
										"提示",
										"找不到这个月的成品率，也可能是查找的数据库不对，是否查找前一个月的成品率？'yes'--是，'no'-退出",
										function(button) {
											if (button == 'yes') {
												if (osm["month1"] == 1) {
													osm["month1"] = 12;
													osm["year1"]--;
												} else
													osm["month1"]--;
												loadmask.show();
												orderSumSub.getProcessYield(
														process["processName"],
														MAP, osm["ssign"],
														process["afterSpec"],
														osm["plate"],
														osm["month1"],
														osm["year1"],
														osm["factory"],
														osm["type"], function(
																ret) {
															loadmask.hide();
															if (ret) {
																runningDs
																		.getAt(num
																				- 1).data["processYield"] = ret;
																runningDs
																		.fireEvent(
																				"update",
																				runningDs,
																				runningDs
																						.getAt(num
																								- 1),
																				4);
																// form.find("name","peifang").setValue(ret);
																Ext.Msg
																		.confirm(
																				"提示:",
																				"加工成品率为："
																						+ ret
																						+ ",'yes'--继续','no'--退出自动'",
																				function(
																						button) {
																					if (button == "no") {
																						processProcedure = 0;// 先退出
																					} else
																						processProcedure = 5;
																				})
															} else {
																Ext.Msg
																		.confirm(
																				"提示",
																				"找不到上个月的成品率，也可能是查找的库表不对，是否用默认的成品率？'yes'--是，'no'-退出",
																				function(
																						button) {
																					if (button == 'yes') {
																						var type = "";
																						//if (process["processName"] == '切片')
																						type = helper.getType(before);
																						if (process["processName"] == '电镀')
																							type = "电镀"
																									+ "_"
																									+ osm["plate"]
																									+ "_"
																									+ osm["ssign"];
																						otherConstants
																								.getOtherConstants(
																										process["processName"]
																												+ "默认成品率",
																										type,
																										function(
																												ret) {
																											if (ret) {
																												runningDs
																														.getAt(num
																																- 1).data["processYield"] = ret;
																												runningDs
																														.fireEvent(
																																"update",
																																runningDs,
																																runningDs
																																		.getAt(num
																																				- 1),
																																4);
																												processProcedure = 5;
																											} else {
																												Ext.Msg
																														.alert(
																																"错误",
																																"没有找到"
																																		+ process["processName"]
																																		+ "默认成品率,可能查找的库表没有设置正确，请联系管理员设置");
																												processProcedure = 0;
																											}
																										});
																					} else
																						processProcedure = 0;

																				})

															}
														});
											} else
												processProcedure = 0;
										})

					}
				});
	}
}
function checkValid(A) {
	var arr = A.split("*");
	for (var i = 0; i < arr.length; i++)
		if (arr[i] < 0.001)
			return false;
	return true;
}
function getQieNum() {
	if (processProcedure == 5) {
		processProcedure = 0;
		var osm = getOSM();
		var process = getOSS();
		var before;
		var num = process["processPos"];
		if (num == 1)
			before = osm["spec_yz"];
		else {
			if (runningDs.getAt(num - 2).data["processName"] == '芯子')
				before = runningDs.getAt(num - 3).data["afterSpec"];
			else
				before = runningDs.getAt(num - 2).data["afterSpec"];
		}

		if (process["processName"] == '切片' || process["processName"] == '线切割') {
			loadmask.show();
			orderSumSub.getQieNum(before, process["afterSpec"],
					process["processName"], osm["year1"], osm["month1"],
					function(ret) {
						loadmask.hide();
						if (ret) {
							// TODO 方块余量
							var arr = ret.split("_");
							var fkStr = "";
							if (arr.length > 1) {
								ret = arr[0];
								if (checkValid(arr[1]))
									fkStr = "剩余方块的余量为：" + arr[1];
							} else
								ret = arr[0];
							runningDs.getAt(num - 1).data["processNum"] = ret;
							runningDs.fireEvent("update", runningDs, runningDs
											.getAt(num - 1), 5);

							Ext.Msg.confirm("提示:", "加工件数为:" + ret + fkStr
											+ ",目前已经结算完毕，是否继续",
									function(button) {
										if (button == "no") {
											processProcedure = 0;// 先退出
										} else
											processProcedure = 6;
									});
						} else {
							processProcedure = 0;
							Ext.Msg.alert("提示", "切片数量无法计算，请联系管理员，添加新的计算方法")
						}
					});
		} else {
			Ext.Msg.confirm("提示:", "目前已经结算完毕，是否继续", function(button) {
						if (button == "no") {
							processProcedure = 0;// 先退出
						} else
							processProcedure = 6;
					});
		}

	}

}
function replaceHopeYield() {
	if (processHopeProcedure == 0)
		return;
	var temp = runningMainDs;
	runningMainDs = ds2;
	var osm = getOSM();
	runningMainDs = temp;
	var kaimoSpec=helper.getType(osm["spec_yz"]);
	switch (processHopeProcedure) {
		case 1 :
			// 读取未磨
			processHopeProcedure = 0;
			loadmask.show();
			otherConstants.getOtherConstants("未磨默认成品率",
					kaimoSpec, function(ret) {
						loadmask.hide();
						if (ret) {
							ds2.getAt(0).data["weimo2"] = ret;
							ds2.fireEvent("update", ds2, ds2.getAt(0));
							Ext.Msg.confirm("提示", "未磨默认成品率为:" + ret
											+ ",'yes'--继续,'no'--退出", function(
											button) {
										if (button == 'yes')
											processHopeProcedure = 2;
									});
						} else {
							Ext.Msg.alert("错误", "没有找到未磨默认成品率,请联系管理员设置");
						}
					});
			break;
		case 2 :
			processHopeProcedure = 0;
			
			loadmask.show();
			if (processDs2.find("processName", "前道磨加工") >= 0
					|| (helper.isFangKuai(osm["spec_yz"]) && (helper
							.isTuoYuan(osm["spec"])
							|| helper.isPaoDao(osm["spec"]) || helper
							.isPaoDaoKong(osm["spec"])))) {
				// 需要将已磨设置为1
				ds2.getAt(0).data["yimo2"] = 1;
				ds2.fireEvent("update", ds2, ds2.getAt(0));
				processHopeProcedure = 3;

			} else
				otherConstants.getOtherConstants("已磨默认成品率",
						kaimoSpec, function(ret) {
							loadmask.hide();
							if (ret) {
								ds2.getAt(0).data["yimo2"] = ret;
								ds2.fireEvent("update", ds2, ds2.getAt(0));
								Ext.Msg.confirm("提示", "已磨默认成品率为:" + ret
												+ ",'yes'--继续,'no'--退出",
										function(button) {
											if (button == 'yes')
												processHopeProcedure = 3;
										});
							} else {
								Ext.Msg.alert("错误", "没有找到已磨默认成品率,请联系管理员设置");
							}
						});
			break;
		case 3 :
			processHopeProcedure = 0;
			loadmask.show();
			otherConstants.getOtherConstants("前道默认成品率", "ssign_"
							+ ds.getAt(0).data["ssign_yz"], function(ret) {
						loadmask.hide();
						if (ret) {
							ds2.getAt(0).data["qiandao_yield2"] = ret;
							ds2.fireEvent("update", ds2, ds2.getAt(0));
							Ext.Msg.confirm("提示", "前道默认收得率为:" + ret
											+ ",'yes'--继续,'no'--退出", function(
											button) {
										if (button == 'yes')
											processHopeProcedure = 4;
									});
						} else {
							Ext.Msg.alert("错误", "没有找到前道默认成品率,请联系管理员设置");
						}
					});
			break;
		case 4 :
			processHopeProcedure = 0;
			loadmask.show();
			orderSumSub.getHopeGrossWeight(osm["ssign_yz"], osm["spec_yz"],
					function(ret) {
						loadmask.hide();
						if (ret) {
							ds2.getAt(0).data["grossweight2"] = ret;
							ds2.fireEvent("update", ds2, ds2.getAt(0));
							Ext.Msg.confirm("提示", "理论毛重为:" + ret
											+ ",'yes'--继续,'no'--退出", function(
											button) {
										if (button == 'yes')
											processHopeProcedure = 5;
									});
						} else {
							Ext.Msg.alert("错误", "没有找到理论毛重,请联系管理员设置");
						}
					});
			break;
		case 5 :
			processHopeProcedure = 0;
			dwr.engine.setAsync(false);
			var before=ds.getAt(0).data["spec_yz"];
			processDs2.each(function(rec) {
				var type = "";
				if (rec.data["processName"] == '切片'
						|| rec.data["processName"] == "前道磨加工")
					type =helper.getType(before);
					logger.debug(rec.data["processName"]+"before:"+before);
				if (rec.data["processName"] == '电镀')
					type = "电镀" + "_" + osm["plate"] + "_" + osm["ssign"];
				otherConstants.getOtherConstants(rec.data["processName"]
								+ "默认成品率", type, function(ret) {
							if (ret) {
								rec.data["processYield"] = ret;
								if (processDs2.getCount() == rec.data["processPos"])
									processDs2.fireEvent("update", processDs2,
											rec);
							} else {
								Ext.Msg.alert("错误", "没有找到"
												+ rec.data["processName"]
												+ "默认成品率,请联系管理员设置");
							}
						});
				before=rec.data["afterSpec"];
			})
			dwr.engine.setAsync(true);

			break;

	}
}

function loopProcess() {
	if (processProcedure == 6) {

		Ext.Msg.confirm("提示：", "是否需要进行下一个加工步骤的结算", function(button) {
			if (button == "yes") {
				var sm = runningGrid.getSelectionModel();
				if (runningSm.getSelections()[0].data["processPos"] == runningDs
						.getCount()) {
					processProcedure = 0;
					return;
				}
				sm.selectNext();
				runningSm = sm;
				processProcedure = 1;
			} else {
				processProcedure = 0;
				return;
			}
		})
	}
}

var fm = Ext.form;
function initGrid1() {
	var sm = new Ext.grid.CheckboxSelectionModel();
	var cm = new Ext.grid.ColumnModel([sm, {
				header : "加工流程编号",
				width : 80,
				dataIndex : 'id',
				editor : new fm.NumberField({
							allowBlank : false
						})
			}, {
				header : "加工步骤",
				width : 80,
				dataIndex : 'processPos',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工名称",
				width : 80,
				dataIndex : 'processName',
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工后规格",
				width : 80,
				dataIndex : 'afterSpec',
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工面积",
				width : 80,
				dataIndex : 'processArea',

				editor : new fm.NumberField({
							allowBlank : false
						})
			}, {
				header : "加工数量",
				width : 80,
				dataIndex : 'processNum',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工单价",
				width : 80,
				dataIndex : 'unitPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工提升公式",
				width : 80,
				dataIndex : 'updateStr',
				hidden : true,
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工提升",
				width : 80,
				dataIndex : 'processUpdate',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工成品率",
				width : 80,
				dataIndex : 'processYield',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "其他费用",
				width : 80,
				dataIndex : 'otherFee',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工总价",
				width : 80,
				dataIndex : 'processPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "到目前为止价格",
				width : 80,
				dataIndex : 'untilPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}]);
	if (!grid)
		grid = new Ext.grid.EditorGridPanel({

					viewConfig : {
						forceFit : false
					},
					autoScroll : true,
					ds : processDs,
					cm : cm,
					sm : sm,
					height : 300,
					width : 350,

					title : '实际加工流程'
				});
}
function initGrid2() {
	var sm = new Ext.grid.CheckboxSelectionModel();
	var cm = new Ext.grid.ColumnModel([sm, {
				header : "加工流程编号",
				width : 80,
				dataIndex : 'id',
				editor : new fm.NumberField({
							allowBlank : false
						})
			}, {
				header : "加工步骤",
				width : 80,
				dataIndex : 'processPos',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工名称",
				width : 80,
				dataIndex : 'processName',
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工后规格",
				width : 80,
				dataIndex : 'afterSpec',
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工面积",
				width : 80,
				dataIndex : 'processArea',

				editor : new fm.NumberField({
							allowBlank : false
						})
			}, {
				header : "加工数量",
				width : 80,
				dataIndex : 'processNum',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工单价",
				width : 80,
				dataIndex : 'unitPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工提升公式",
				width : 80,
				dataIndex : 'updateStr',
				hidden : true,
				editor : new fm.TextField({
							allowBlank : false
						})

			}, {
				header : "加工提升",
				width : 80,
				dataIndex : 'processUpdate',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工成品率",
				width : 80,
				dataIndex : 'processYield',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "其他费用",
				width : 80,
				dataIndex : 'otherFee',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "加工总价",
				width : 80,
				dataIndex : 'processPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}, {
				header : "到目前为止价格",
				width : 80,
				dataIndex : 'untilPrice',
				editor : new fm.NumberField({
							allowBlank : false
						})

			}]);
	if (!grid2)
		grid2 = new Ext.grid.EditorGridPanel({

					viewConfig : {
						forceFit : false
					},
					autoScroll : true,
					ds : processDs2,
					cm : cm,
					sm : sm,
					height : 300,
					width : 350,

					title : '实际加工流程'
				});
}
function initDs2() {
	ds2 = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : '../ordersummain.do?action=list&id=' + id2
						}),

				reader : new Ext.data.JsonReader({
							root : 'root'
						}, [{
									name : 'id2',
									mapping : 'id'

								}, {
									name : 'spec2',
									mapping : 'spec'
								}, {
									name : 'factory2',
									mapping : 'factory'

								}, {
									name : 'transnum2',
									mapping : 'transnum'
								}, {
									name : 'ordernum2',
									mapping : 'ordernum'
								}, {
									name : 'ssign2',
									mapping : 'ssign'
								}, {
									name : 'ssign_yz2',
									mapping : 'ssign_yz'
								}, {
									name : 'grossweight2',
									type : 'float',
									mapping : 'grossweight'
								}, {
									name : 'qiandao_yield2',
									type : 'float',
									mapping : 'qiandao_yield'
								}, {
									name : 'yimo2',
									type : 'float',
									mapping : 'yimo'
								}, {
									name : 'weimo2',
									type : 'float',
									mapping : 'weimo'
								}, {
									name : 'feipin2',
									type : 'float',
									mapping : 'feipin'
								}, {
									name : 'qiandao_cost2',
									type : 'float',
									mapping : 'qiandao_cost'
								}, {
									name : 'product_cost_before2',
									type : 'float',
									mapping : 'product_cost_before'
								}, {
									name : 'specType2',
									mapping : 'specType'
								}, {
									name : 'processScheme2',
									mapping : 'processScheme'
								}, {
									name : 'plate2',
									mapping : 'plate'
								}, {
									name : 'baozhuangfei2',
									type : 'float',
									mapping : 'baozhuangfei'
								}, {
									name : 'houdao_yield2',
									type : 'float',
									mapping : 'houdao_yield'
								}, {
									name : 'product_cost_last2',
									type : 'float',
									mapping : 'product_cost_last'
								}, {
									name : 'date12',
									mapping : 'date1'
								}, {
									name : 'ordercost2',
									type : 'float',
									mapping : 'ordercost'
								}, {
									name : 'lirun2',
									type : 'float',
									mapping : 'lirun'
								}, {
									name : 'bz2',
									mapping : 'bz'
								}, {
									name : 'maker2',
									mapping : 'maker'
								}, {
									name : 'makeDate2',
									mapping : 'makeDate'
								}, {
									name : 'type2',
									mapping : 'type'
								}, {
									name : 'peifang2',
									type : 'float',
									mapping : 'peifang'
								}, {
									name : 'spec_yz2',
									mapping : 'spec_yz'
								}, {
									name : 'month12',
									mapping : 'month1'
								}, {
									name : 'year12',
									mapping : 'year1'
								}, {
									name : 'status2',
									mapping : 'status'
								}])
			});

	ds2.load({
				params : {
					start : 0
				},
				callback : function(records, o, s) {
					flag++;
					if (s)
						form.getForm().loadRecord(ds2.getAt(0));
				}
			});
	ds2.on("update", function(_this, _rec, _opt) {
		var A = ds2.getAt(0).data["peifang2"];
		var B = ds2.getAt(0).data["qiandao_yield2"];
		var C = ds2.getAt(0).data["weimo2"];
		var D = ds2.getAt(0).data["yimo2"];
		var E = ds2.getAt(0).data["grossweight2"];
		var F = ds2.getAt(0).data["feipin2"];
		var G = ds2.getAt(0).data["qiandao_cost2"];
		var H = ds2.getAt(0).data["ordercost2"];

		ds2.getAt(0).data["product_cost_before2"] = calcProductCostBefore(A, B,
				C, D, E, F, G);
		if (processDs2.getCount() > 0 && _opt != "noloop")
			processDs2.fireEvent("update", processDs2, processDs2.getAt(0),
					"noloop");
		ds2.getAt(0).data["houdao_yield2"] = calcHouDao(
				ds2.getAt(0).data["specType"], processDs2);
		if (processDs2.getCount() != 0)
			ds2.getAt(0).data["product_cost_last2"] = calcProductCostLast(
					ds2.getAt(0).data["baozhuangfei2"],
					processDs2.getAt(processDs2.getCount() - 1).data["untilPrice"]);

		var I = ds2.getAt(0).data["product_cost_last2"];
		// alert(I);
		ds2.getAt(0).data["lirun2"] = calcLiRun(H, I);

		loadRecord();
		ds2Dirty = true;
	})
}
function initProcessDs() {
	processDs = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : '../ordersumsub.do?action=list&orderSumId='
									+ id
						}),

				reader : new Ext.data.JsonReader({
							root : 'root'
						}, [{
									name : 'id'
								}, {
									name : 'orderSumId'
								}, {
									name : 'processName'
								}, {
									name : 'afterSpec'
								}, {
									type : 'float',
									name : 'processYield'

								}, {
									type : 'float',
									name : 'processUpdate'
								}, {
									type : 'float',
									name : 'unitPrice'
								}, {
									type : 'float',
									name : 'processArea'
								}, {
									type : 'float',
									name : 'processPrice'
								}, {
									type : 'float',
									name : 'untilPrice'
								}, {
									name : 'type'
								}, {
									type : 'float',
									name : 'processNum'
								}, {
									type : 'float',
									name : 'processPos'
								}, {
									type : 'float',
									name : 'otherFee'
								}, {
									name : 'status'
								}, {
									name : 'updateStr'
								}])
			});
	processDs.load({
				params : {

					test : 11
				},

				callback : function(records, o, s) {
					flag++;
					if (s) {
						if (ds.getCount() > 0) {
							calcAllUntilPrice(ds, processDs,
									ds.getAt(0).data["type"]);
							ds.fireEvent("update", ds, ds.getAt(0), "noloop");
						}
						// processDsDirty = ALLDIRTY;
						dwr.engine.setAsync(false);
						saveAllProcess(processDs);
						dwr.engine.setAsync(true);
						grid.getView().refresh();
					}
				}
			});
	processDs.on("update", function(_this, _rec, opt) {
		// 这个update函数是人为的调用的。
		if (!opt)
			opt = "";
		if (_rec.data["processUpdate"] == 0)
			_rec.data["processUpdate"] = 1;
		_rec.data["processPrice"] = (_rec.data["processArea"] * _rec.data["unitPrice"])
				* _rec.data["processUpdate"];
		_rec.data["processPrice"] = tofloat(_rec.data["processPrice"]);

		calcAllUntilPrice(ds, processDs, ds.getAt(0).data["type"],
				_rec.data["processPos"]);
		processDsDirty = _rec.data["processPos"];
		if (opt != "noloop")
			ds.fireEvent("update", ds, ds.getAt(0));

		loadRecord();
		grid.getView().refresh();
	})
	/*
	 * processDs.load({ params : { start : 0 },
	 * 
	 * callback : function(records, o, s) { flag++; if (s) {
	 * processDs.each(function i(_rec) { //_rec.data["status"] =
	 * statusArr[_rec.data["type"]]; }) grid.getView().refresh(); } } });
	 */
}
function tofloat(f, dec) {
	if (isNaN(f))
		return 0;
	if (!dec)
		dec = 5;

	if (dec < 0)
		return "Error:dec<0!";
	var temp = 1;
	for (var i = 0; i < dec; i++)
		temp *= 10;
	f *= temp;
	f = Math.round(f);
	// alert(f/temp);
	return f / temp;
}

function initProcessDs2() {
	processDs2 = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : '../ordersumsub.do?action=list&orderSumId='
									+ id2
						}),

				reader : new Ext.data.JsonReader({
							root : 'root'
						}, [{
									name : 'id'
								}, {
									name : 'orderSumId'
								}, {
									name : 'processName'
								}, {
									name : 'afterSpec'
								}, {
									type : 'float',
									name : 'processYield'
								}, {
									type : 'float',
									name : 'processUpdate'
								}, {
									type : 'float',
									name : 'unitPrice'
								}, {
									type : 'float',
									name : 'processArea'
								}, {
									type : 'float',
									name : 'processPrice'
								}, {
									type : 'float',
									name : 'untilPrice'
								}, {
									name : 'type'
								}, {
									type : 'float',
									name : 'processNum'
								}, {
									type : 'float',
									name : 'processPos'
								}, {
									type : 'float',
									name : 'otherFee'
								}, {
									name : 'status'
								}, {
									name : 'updateStr'
								}])
			});
	processDs2.load({
				params : {

					test : 11
				},

				callback : function(records, o, s) {
					if (s) {
						if (ds2.getCount() > 0) {
							calcAllUntilPrice(ds2, processDs2,
									ds2.getAt(0).data["type2"]);
							ds2
									.fireEvent("update", ds2, ds2.getAt(0),
											"noloop");
						}
						dwr.engine.setAsync(false);
						saveAllProcess(processDs2);
						dwr.engine.setAsync(true);

						grid2.getView().refresh();
					}
				}
			});
	processDs2.on("update", function(_this, _rec, opt) {
		// 这个update函数是人为的调用的。
		if (!opt)
			opt = "";
		if (_rec.data["processUpdate"] == 0)
			_rec.data["processUpdate"] = 1;
		_rec.data["processPrice"] = (_rec.data["processArea"] * _rec.data["unitPrice"])
				* _rec.data["processUpdate"];
		_rec.data["processPrice"] = tofloat(_rec.data["processPrice"]);
		/*
		 * var before = _rec.data["processPos"];
		 * 
		 * if (before == 1) before = ds2.getAt(0).data["product_cost_before2"];
		 * else before = processDs2.getAt(before - 2).data["untilPrice"]; if
		 * (_rec.data["processNum"] > 0 && _rec.data["processYield"] > 0)
		 * _rec.data["untilPrice"] = (before / _rec.data["processNum"] +
		 * _rec.data["processPrice"]) / _rec.data["processYield"] +
		 * _rec.data["otherFee"]; //
		 * alert(before+":"+_rec.data["processNum"]+":"+_rec.data["processPrice"]+":"+_rec.data["processYield"]+":"+_rec.data["otherFee"]+":"+_rec.data["untilPrice"]);
		 * _rec.data["untilPrice"] = tofloat(_rec.data["untilPrice"]);
		 */
		calcAllUntilPrice(ds2, processDs2, ds2.getAt(0).data["type2"],
				_rec.data["processPos"]);

		if (opt != "noloop")
			ds2.fireEvent("update", ds2, ds2.getAt(0));
		/*
		 * if (_rec.data["processPos"] == _this.getCount()) {
		 * ds2.getAt(0).data["houdao_yield"] = tofloat(calcHouDao(_this));
		 * ds2.fireEvent("update", ds2, ds2.getAt(0)); }
		 */

		loadRecord();
		processDs2Dirty = _rec.data["processPos"];
		grid2.getView().refresh();
	})
	/*
	 * processDs2.load({ params : { start : 0 },
	 * 
	 * callback : function(records, o, s) { flag++; if (s) {
	 * processDs2.each(function i(_rec) { //_rec.data["status"] =
	 * statusArr[_rec.data["type"]]; }) grid2.getView().refresh(); } } });
	 */
}
function getLoadMask() {
	if (!loadmask)
		loadmask = new Ext.LoadMask(Ext.get("main_form"), {
					msg : '请等待一下，系统正在进行操作，请勿点击其他操作'
				});

	return loadmask;
}

function waitForTime() {
	window.setTimeout('doShow()', WAITTIME);
}
function loadRecord() {
	// 只有在自动读取的时候才会需要从store更新form。
	if (form) {
		// if (procedure!=0)
		if (ds.getCount() > 0)
			form.getForm().loadRecord(ds.getAt(0));
		if (ds2.getCount() > 0)
			form.getForm().loadRecord(ds2.getAt(0));
		// }
	}
	if (updateForm && updateForm.isVisible()) {
		updateForm.getForm().loadRecord(runningSm.getSelections()[0]);
		if (runningSm.getSelections()[0].data["processName"] == "电镀") {
			updateForm.find("name", "processName")[0].setValue("电镀" + "("
					+ form.find("name", "plate")[0].getValue() + ")");
		}
		if (form.find("name", "specType")[0].getValue() == 'taokong') {
			var arr = form.find("name", "spec")[0].getValue().split("*");
			if (arr.length != 3)
				return;
			// updateForm.find("name","processName")[0].show();
			var a0 = arr[0].split("$");
			var a1 = arr[1].split("$");
			updateForm.find("name", "bihou")[0]
					.setValue(tofloat((a0[1] - a1[1]) / 2));
		}
	}
}
function processAction() {
	updateForm = getUpdateForm();
	var sm = runningGrid.getSelectionModel();
	runningSm = sm;
	var items = new Ext.util.MixedCollection();
	items.add("updateForm", updateForm);
	win = getWin();

	win.items = items;

	hideWin(win);

	win.show();
	if (dataForm)
		dataForm.hide();
	updateForm.show();
	win.setHeight(500);
	updateForm.getForm().reset();
	updateForm.getForm().loadRecord(sm.getSelected());

}

function runningFunction() {
	timeId3 = window.setInterval('createOSS()', WAITTIME);
	timeId4 = window.setInterval("getPeiFang()", WAITTIME);
	timeId5 = window.setInterval("getWeiMo()", WAITTIME);
	timeId6 = window.setInterval("getYiMo()", WAITTIME);
	timeId7 = window.setInterval("getGrossWeight()", WAITTIME);
	timeId8 = window.setInterval("getQianDaoYield()", WAITTIME);
	timeId9 = window.setInterval("getFeiPin()", WAITTIME);
	timeId10 = window.setInterval("getQianDaoFee()", WAITTIME);
	timeId11 = window.setInterval("getBaoZhuangFee()", WAITTIME);
	timeId12 = window.setInterval("replaceHopeYield()", WAITTIME);

	timeId13 = window.setInterval("getProcessSpec()", WAITTIME);
	timeId14 = window.setInterval("getQieNum()", WAITTIME);
	timeId15 = window.setInterval("getProcessArea()", WAITTIME);

	timeId16 = window.setInterval("getProcessFee()", WAITTIME);
	timeId17 = window.setInterval("getProcessYield()", WAITTIME);

	timeId18 = window.setInterval("loopProcess()", 5 * WAITTIME);
	timeId19 = window.setInterval("readKaiMo()", WAITTIME);

}
function getUpdateForm() {
	if (!updateForm) {
		updateForm = new Ext.FormPanel({
			labelWidth : 75,
			frame : true,
			bodyStyle : 'padding:5px 5px 0',
			width : 340,
			defaults : {
				width : 230
			},
			defaultType : 'textfield',
			items : [{
						fieldLabel : '编号',// 一开始漏了个主id,导致update不成功
						name : 'id',
						readOnly : true,
						listeners : {
							"specialkey" : function(_this, e) {
								// alert("specialkey");
								if (e == Ext.EventObject.RIGHT) {
									// alert("right");

								}
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '对应主订单编号',// 一开始漏了个主id,导致update不成功
						name : 'orderSumId',
						readOnly : true,
						allowBlank : false
					}, {
						fieldLabel : '加工名称',// 一开始漏了个主id,导致update不成功
						name : 'processName',
						readOnly : true,
						allowBlank : false
					}, {
						fieldLabel : '加工步骤',// 一开始漏了个主id,导致update不成功
						name : 'processPos',
						readOnly : true,
						allowBlank : false
					}, {
						fieldLabel : '加工后规格',// 一开始漏了个主id,导致update不成功
						name : 'afterSpec',
						listeners : {
							"change" : function(_this, _new, _old) {

								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["afterSpec"] = _new;
								// 开始自动计算加工面积。
								processProcedure = 2;
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '加工数量',// 一开始漏了个主id,导致update不成功
						name : 'processNum',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {

								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["processNum"] = _new;
								runningDs.fireEvent("update", runningDs, rec);
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '加工面积',// 一开始漏了个主id,导致update不成功
						name : 'processArea',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								_new = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["processArea"] = _new;
								runningDs.fireEvent("update", runningDs, rec);
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '加工单价',// 一开始漏了个主id,导致update不成功
						name : 'unitPrice',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								_new = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								if (_new > MAXFEE) {
									Ext.Msg
											.confirm(
													"提示",
													"该加工费价格可能是整个加工费的价格，是否需要除以加工面积，方便规整化计算？",
													function(button) {
														if (button == 'yes') {
															rec.data["unitPrice"] = tofloat(_new
																	/ rec.data["processArea"]);
															runningDs
																	.fireEvent(
																			"update",
																			runningDs,
																			rec);
														} else {
															rec.data["unitPrice"] = _new;
															runningDs
																	.fireEvent(
																			"update",
																			runningDs,
																			rec);
														}

													});

								} else {
									rec.data["unitPrice"] = _new;
									runningDs.fireEvent("update", runningDs,
											rec);
								}

							}
						},
						allowBlank : false
					}, {
						fieldLabel : '产品璧厚',// 一开始漏了个主id,导致update不成功
						name : 'bihou',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
							}
						},
						readOnly : true,
						// hidden : true,
						allowBlank : false
					}, {
						fieldLabel : '加工提升公式',// 一开始漏了个主id,导致update不成功
						name : 'updateStr',
						// xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								var ret = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["updateStr"] = _new;
								rec.data["processUpdate"] = ret;
								runningDs.fireEvent("update", runningDs, rec);
								updateForm.find("name", "processUpdate")[0]
										.setValue(ret);
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '加工提升',// 一开始漏了个主id,导致update不成功
						name : 'processUpdate',
						xtype : 'numberfield',
						decimalPrecision : 6,

						readOnly : true,
						allowBlank : false
					}, {
						fieldLabel : '加工成品率',// 一开始漏了个主id,导致update不成功
						name : 'processYield',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								_new = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["processYield"] = _new;
								runningDs.fireEvent("update", runningDs, rec);
							}
						},
						allowBlank : false
					}, {
						fieldLabel : '其他费用',// 一开始漏了个主id,导致update不成功
						name : 'otherFee',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								_new = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["otherFee"] = _new;
								runningDs.fireEvent("update", runningDs, rec);
							}
						},

						allowBlank : false
					}, {
						fieldLabel : '加工费用',// 一开始漏了个主id,导致update不成功
						name : 'processPrice',
						xtype : 'numberfield',
						decimalPrecision : 6,
						listeners : {
							"change" : function(_this, _new, _old) {
								_new = tofloat(eval(_new));
								var sm = runningGrid.getSelectionModel();
								var rec = sm.getSelections()[0];
								rec.data["processPrice"] = _new;
								Ext.Msg.confirm("提示", "是否需要将这个作为总的加工费？",
										function(button) {
											if (button == 'yes') {
												// TODO 系统自动修改产品单价
												var u = rec.data["unitPrice"];
												var area = rec.data["processArea"];
												var up = rec.data["processUpdate"];
												rec.data["unitPrice"] = tofloat(_new
														/ up / area);
											}
											runningDs.fireEvent("update",
													runningDs, rec);
										});

							}
						},

						allowBlank : false
					}, {
						fieldLabel : '到目前为止费用',// 一开始漏了个主id,导致update不成功
						name : 'untilPrice',
						xtype : 'numberfield',
						decimalPrecision : 6,
						readOnly : true,
						allowBlank : false
					}]
		});
		updateForm.on("show", function(_this) {
					if (updateForm.isVisible())
						processProcedure = 1;
				});
	}
	return updateForm;
}
function initGrid() {
	Ext.QuickTips.init();

	var xg = Ext.grid;

	// win

	// Grid
	var sm = new xg.CheckboxSelectionModel();
	form = new Ext.FormPanel({
		renderTo : 'main',
		id : 'main_form',
		url : '../orderJieSuan.do?action=saveAll',
		labelAlign : 'left',
		title : '结算订单',
		buttonAlign : 'right',
		bodyStyle : 'padding:5px;',
		frame : true,// 设置了面板的边角是圆弧过度的，底色
		labelWidth : 80,
		height : 800,
		width : 800,
		autoScroll : true,
		layout : 'border',

		items : [{
			region : 'west',
			layout : 'column',
			autoHeight : true,
			width : 400,

			split : true,
			items : [{
						columnWidth : 1,
						title : '目标结算信息',
						anchor : '95%',
						autoHeight : true,
						hideBorders : true

					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标基本信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,
						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '编号',
									border : false,
									readOnly : true,
									name : 'id2',
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '年份',
									readOnly : true,
									// value : _cus.attn,
									name : "year12",
									anchor : '90%',
									border : false

								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '月份',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "month12",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '规格',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "spec2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '牌号',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "ssign2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									border : false,
									fieldLabel : '订单号',

									readOnly : true,
									// value : _cus.attn,
									name : "transnum2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单数量',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "ordernum2",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标毛坯信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,

						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '分厂号',
									border : false,
									// readOnly : true,
									name : "factory2",
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["factory2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '入库牌号',

									border : false,

									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["ssign_yz2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// readOnly : true,
									name : "ssign_yz2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '入库规格',

									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["spec_yz2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
											Ext.Msg
													.confirm(
															"提示",
															"是否需要重新计算下毛重？'yes'--是，'no'--不需要",
															function(button) {
																if (button == 'yes') {
																	processHopeProcedure = 4;
																}

															})
										}
									},
									// readOnly : true,
									border : false,
									name : "spec_yz2",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标毛坯加工信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,

						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '配方价格',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["peifang2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "peifang2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '前道收得率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											alert(_new);
											ds2.getAt(0).data["qiandao_yield2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "qiandao_yield2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '默认毛重',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["weimo2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "weimo2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '已磨成品率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["yimo2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "yimo2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '毛重',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["grossweight2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "grossweight2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '废品率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["feipin2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "feipin2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '前道费用',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["qiandao_cost2"] = _new;
											ds2.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "qiandao_cost2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '产品入库成本',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["product_cost_before2"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},

									// readOnly : true,
									// value : _cus.attn,
									name : "product_cost_before2",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标加工信息',
						collapsible : true,

						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '规格类型',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "specType2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '加工流程编号',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "processScheme2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '镀层',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "plate2",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标详细加工费',
						collapsible : true,
						// collapsed : true,
						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,

						items : grid2

					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '目标剩余结算信息',
						collapsible : true,

						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',

									border : false,

									// readOnly : true,
									// value : _cus.attn,
									fieldLabel : '包装费',
									// readOnly : true,
									// value : _cus.attn,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["baozhuangfei2"] = _new;
											ds2.fireEvent("update", ds2, ds2
															.getAt(0));
										}
									},
									name : "baozhuangfei2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',

									border : false,

									fieldLabel : '后道成品率',
									// readOnly : true,
									// value : _cus.attn,
									name : "houdao_yield2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单成本',
									// readOnly : true,
									// value : _cus.attn,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds2.getAt(0).data["product_cost_last2"] = _new;
											ds2.fireEvent("update", ds2, ds2
															.getAt(0));
										}
									},
									name : "product_cost_last2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单发货日期',
									// readOnly : true,
									// value : _cus.attn,
									name : "date12",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单价格',
									// readOnly : true,
									// value : _cus.attn,
									name : "ordercost2",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '利润',
									// readOnly : true,
									// value : _cus.attn,
									name : "lirun2",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '结算人',
									// readOnly : true,
									// value : _cus.attn,
									allowBlank : false,
									name : "maker2",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '结算日期',
									// readOnly : true,
									// value : _cus.attn,
									name : "makeDate2",

									anchor : '90%'
								}]
					}]
		}, {
			region : 'center',
			layout : 'column',
			autoHeight : true,
			// /width : 400,
			split : true,
			items : [{
						columnWidth : 1,

						title : '实际结算信息',

						anchor : '95%',
						autoHeight : true,
						hideBorders : true

					}, {

						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际基本信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,

						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '编号',
									border : false,
									readOnly : true,

									name : 'id',
									anchor : '90%'

								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '年份',
									readOnly : true,
									// value : _cus.attn,
									name : "year1",
									anchor : '90%',
									border : false

								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '月份',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "month1",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '规格',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "spec",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '牌号',
									border : false,

									readOnly : true,
									// value : _cus.attn,
									name : "ssign",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									border : false,
									fieldLabel : '订单号',

									readOnly : true,
									// value : _cus.attn,
									name : "transnum",
									xtype : 'combo',
									store : transnumDs,
									valueField : 'transnum',
									displayField : 'transnum',
									typeAhead : true,
									mode : 'local',
									triggerAction : 'all',

									selectOnFocus : true,
									forceSelection : true,

									editable : true,
									listeners : {
										"select" : function(_combox, _rec,
												_index) {
											var transnum = _rec.data['transnum'];

											ds.getAt(0).data["transnum"] = transnum;
											ds.fireEvent("update", ds, ds
															.getAt(0));

											Ext.Msg
													.confirm(
															"提示，",
															"是否需要开始更新整个结算过程？'yes'--是，'no'--等会再结算",
															function(button) {
																if (button == 'yes') {
																	runningMainDs = ds;
																	runningGrid = grid;
																	procedure = 1;

																}

															})

										}
									},
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单数量',
									border : false,

									readOnly : true,

									// value : _cus.attn,
									name : "ordernum",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际毛坯信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,

						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '分厂号',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["factory"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// readOnly : true,
									name : "factory",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '入库牌号',
									border : false,
									// readOnly : true,
									name : "ssign_yz",

									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["ssign_yz"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '入库规格',
									border : false,
									// readOnly : true,
									name : "spec_yz",

									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["spec_yz"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际毛坯加工信息',
						collapsible : true,
						collapsed : true,
						anchor : '95%',
						autoHeight : true,

						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '配方价格',
									border : false,

									// readOnly : true,
									// value : _cus.attn,
									name : "peifang",
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["peifang"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '前道收得率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["qiandao_yield"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r

									// readOnly : true,
									// value : _cus.attn,
									name : "qiandao_yield",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '未磨成品率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["weimo"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r

									// readOnly : true,
									// value : _cus.attn,
									name : "weimo",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '已磨成品率',
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["yimo"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									border : false,

									// readOnly : true,
									// value : _cus.attn,
									name : "yimo",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '毛重',
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["grossweight"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									border : false,

									// readOnly : true,
									// value : _cus.attn,
									name : "grossweight",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '废品率',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["feipin"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r

									// readOnly : true,
									// value : _cus.attn,
									name : "feipin",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '前道费用',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											// alert(_new);
											ds.getAt(0).data["qiandao_cost"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									// /readOnly : true,
									// value : _cus.attn,
									name : "qiandao_cost",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '产品入库成本',
									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["product_cost_before"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									// r
									// readOnly : true,
									// value : _cus.attn,
									name : "product_cost_before",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际加工信息',
						collapsible : true,

						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									fieldLabel : '规格类型',
									readOnly : true,
									// value : _cus.attn,
									name : "specType",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '加工流程编号',
									border : false,

									readOnly : true,

									name : "processScheme",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '镀层',
									readOnly : true,
									// value : _cus.attn,
									name : "plate",
									anchor : '90%'
								}]
					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际详细加工费',
						collapsible : true,
						// collapsed : true,
						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,

						items : grid

					}, {
						columnWidth : 1,
						layout : 'form',
						xtype : 'fieldset',
						title : '实际剩余结算信息',
						collapsible : true,

						anchor : '95%',
						autoHeight : true,
						// collapsed : true,
						hideBorders : true,
						defaultType : 'textfield',
						items : [{
									columnWidth : 1,
									layout : 'form',

									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									// value : _cus.attn,
									fieldLabel : '包装费',
									// readOnly : true,
									// value : _cus.attn,
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["baozhuangfei"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
											/*
											 * form.find("name",
											 * "product_cost_last")[0]
											 * .setValue((parseFloat(_new) +
											 * parseFloat(processDs
											 * .getAt(processDs .getCount() -
											 * 1).data["untilPrice"])) / 0.99);
											 * form.find("name",
											 * "product_cost_last")[0]
											 * .fireEvent("change");
											 */
										}
									},
									name : "baozhuangfei",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',

									border : false,
									xtype : 'numberfield',
									decimalPrecision : 6,
									fieldLabel : '后道成品率',
									// readOnly : true,
									// value : _cus.attn,
									name : "houdao_yield",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单成本',
									// readOnly : true,
									// value : _cus.attn,
									name : "product_cost_last",
									listeners : {
										"change" : function(_this, _new, _old) {
											ds.getAt(0).data["product_cost_last"] = _new;
											ds.fireEvent("update", ds, ds
															.getAt(0));
										}
									},
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单发货日期',
									// readOnly : true,
									// value : _cus.attn,
									name : "date1",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '订单价格',
									// readOnly : true,
									// value : _cus.attn,
									name : "ordercost",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '利润',
									// readOnly : true,
									// / value : _cus.attn,
									name : "lirun",
									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '结算人',
									// readOnly : true,
									// value : _cus.attn,
									allowBlank : false,
									name : "maker",

									anchor : '90%'
								}, {
									columnWidth : 1,
									layout : 'form',
									fieldLabel : '结算日期',
									// readOnly : true,
									// value : _cus.attn,
									name : "makeDate",

									anchor : '90%'
								}]
					}]
		}],
		tbar : [{
					text : '半自动结算',
					iconCls : '-add',
					style : 'width:100px;',
					onClick : function() {
						runningMainDs = ds;
						runningGrid = grid;
						procedureWin = getProcedureWin();
						procedureWinFlag = 0;
						procedureWin.setTitle("结算的开始步骤");
						procedureDs.loadData(procedureDsArr1);
						procedureWin.show();
					}
				}, '-', {
					text : '结算加工费',
					iconCls : '-add',
					onClick : function() {

						var sm1 = grid.getSelectionModel();
						var sm2 = grid2.getSelectionModel();
						if (sm1.getCount() == 1 && sm2.getCount() == 0) {
							// 先把数据读取到form中，然后在逐个的进行读取需要的数据。
							runningGrid = grid;
							runningDs = processDs;
							runningMainDs = ds;
							procedureWin = getProcedureWin();
							procedureWinFlag = 1;
							procedureWin.setTitle("结算的加工开始步骤");

							procedureDs.loadData(procedureDsArr2);
							procedureWin.show();

							// 1,读取切片后的规格
						} else if (sm2.getCount() == 1) {
							runningGrid = grid2;
							runningDs = processDs2;
							runningMainDs = ds2;
							procedureWinFlag = 1;
							procedureWin = getProcedureWin();
							procedureWin.setTitle("结算的加工开始步骤");
							procedureDs.loadData(procedureDsArr2);
							procedureWin.show();
						} else {
							Ext.MessageBox.alert('提示', '请选择一条记录！');
						}

					}
				}, '-', {
					text : '目标成品率',
					iconCls : '-add',
					onClick : function() {
						procedureWinFlag = 2;
						procedureWin = getProcedureWin();
						procedureWin.setTitle("选择从哪个步骤开始替换");
						procedureDs.loadData(procedureDsArr3);
						procedureWin.show();

					}
				}, '-', {
					text : '复制到目标',
					iconCls : '-add',
					onClick : function() {
						Ext.Msg.confirm("提示：", "是否需要将实际的复制到目标?", function(
								button) {
							if (button == 'yes') {
								loadmask.show();
								copyToDs2(ds, ds2);
								ds2.fireEvent("update", ds2, ds2.getAt(0));
								copyToProcessDs2(processDs, processDs2);
								dwr.engine.setAsync(false);

								var count = 0;
								processDs2.each(function(rec) {
									// 先创建，再更新。
									rec.data["type"] = 0;
									rec.data["orderSumId"] = ds2.getAt(0).data["id2"];

									orderSumSub.createOrderSumSub(convert(rec),
											function(ret) {
												if (!ret)
													;
												else {
													// alert(ret);
													rec.data["id"] = ret;
													count++;
													if (count == processDs2
															.getCount()) {
														grid.getView()
																.refresh();
														grid2.getView()
																.refresh();
														loadmask.hide();
													}
												}

											});
								});

								// 读取processDs2的数据。

								dwr.engine.setAsync(true);
							}

						});

					}
				}, '-', {
					text : '更改流程',
					iconCls : '-add',
					onClick : function() {
						Ext.Msg
								.confirm(
										"提示：",
										"是否需要更改加工流程编号,如果原来已经存在的将被删除，无法恢复，继续吗?'yes'--继续，'no'--退出",
										function(button) {
											if (button == 'yes') {
												// 更改加工流程的话，需要先弹出选择框
												procedureWinFlag = 3;
												procedureWin = getProcedureWin();
												procedureWin
														.setTitle("目前所有的该规格的加工流程");
												procedureDs.loadData(schemeArr);

												procedureWin.show();
											}

										});

					}
				}, '-', {
					text : '查找规格',
					iconCls : '-add',
					onClick : function() {
						procedureWinFlag = 4;
						mapWin = getMapWin();
						if (mapWin.isVisible())
							return;
						mapWin.show();
					}
				}, '-', {
					text : '保存结算',
					iconCls : '-add',
					onClick : function() {
						Ext.MessageBox.confirm('提示', '保存信息?', function(button) {
									if (button == 'yes') {
										if (form.getForm().isValid()) {
											saveOrderSumMain();
											saveOrderSumSub();
											// 通過dwr來保存
										}
									}
								});
					}
				}, '-', {
					text : '撤销结算',
					iconCls : '-add',
					onClick : function() {
						Ext.MessageBox.confirm('提示',
								"是否需要撤销目前的这两个订单结算的信息'yes'--是,'no'--否",
								function(button) {
									if (button == 'yes') {
										orderSumMain.removeOSM(id,
												function(ret) {
													if (ret) {
														orderSumMain.removeOSM(
																id2, function(
																		ret) {
																	if (ret) {
																		window.location.href = "orderInf.jsp";
																	} else {
																		Ext.Msg
																				.confirm(
																						"错误",
																						"删除订单号"
																								+ id2
																								+ "遇到了错误，请联系管理员,'yes'--是返回发货界面，'no'--返回订单查询界面",
																						function(
																								button) {
																							if (button == 'yes') {
																								window.location.href = "orderInf.jsp";
																							} else
																								window.location.href = "orderSearchIndex.jsp";

																						});
																	}
																})
													} else {
														Ext.Msg
																.confirm(
																		"错误",
																		"删除订单号"
																				+ id
																				+ "遇到了错误，请联系管理员,'yes'--是返回发货界面，'no'--返回订单查询界面",
																		function(
																				button) {
																			if (button == 'yes') {
																				window.location.href = "orderInf.jsp";
																			} else
																				window.location.href = "orderSearchIndex.jsp";

																		});
													}

												});
									}
								});
					}
				}, '-', {
					text : '导出到excel',
					iconCls : '-add',
					onClick : function() {
						// Ext.Msg.alert("提示", "对不起，这个功能暂时在添加中，请等待。。");

						orderExcel.removeAll();
						var arr = [];
						var obj1 = {};
						var obj2 = {};

						obj1.data = convert(ds.getAt(0));
						obj2.data = convert(ds2.getAt(0));
						obj1.data.status = hopeOrReal[obj1.data["type"]];
						obj2.data.status = hopeOrReal[obj2.data["type"]];
						arr.push(obj1);
						arr.push(obj2);
						var s = arr[0].data["specType"];
						var p = arr[0].data["processScheme"];
						// alert(ds2.getAt(0).data["specType"]+"::"+s);
						for (var i = 1; i < arr.length; i++) {
							if (arr[i].data["specType"] != s) {
								Ext.Msg.alert("提示", "加工规格不一致:"
												+ arr[i].data["specType"]);
								return;
							}
							if (arr[i].data["processScheme"] != p) {

								Ext.Msg.alert("提示", "加工流程不一致:"
												+ arr[i].data["processScheme"]);
								return;
							}

						}
						// 进行转换。

						stepStore.load({
							params : {
								scheme : p,
								sortType : s
							},
							callback : function(_ret) {
								// alert("start");
								indicator = 1;
								// tab = convertTab(arr);
								orderExcel.setProcessStore(stepStore);
								// ossList = convertStore(arr, tab);
								// 这里需要提出选择的tab
								var sm = new Ext.grid.CheckboxSelectionModel();
								cm = new Ext.grid.ColumnModel([sm, {
											header : "标签名字",
											width : 150,
											sortable : true,
											dataIndex : 'tabName'
										}, {
											header : "标签位置",
											width : 100,
											sortable : true,
											dataIndex : 'tabId'
										}]);

								var list = [];
								for (var i = 0; i < orderExcel.getName().length; i++) {
									var r = new disableRecord({
												tabName : orderExcel.getName()[i],
												tabId : i
											});
									var dis = [orderExcel.getName()[i], i];
									list.push(dis);
								}
								// 将加工细节先添加进去。
								procedure = -1;
								dwr.engine.setAsync(false);
								for (var i = 0; i < arr.length; i++) {
									orderSumSub.findOrderSumSubs(
											arr[i].data["id"],
											arr[i].data["type"],
											function(data) {

												orderExcel.readData(arr[i],
														data);
											});
								}
								showDs = new Ext.data.SimpleStore({
											fields : ['tabName', 'tabId'],
											data : list
										});

								showDataList(showDs, "选择导出到excel的标签");

								dwr.engine.setAsync(true);

								//
								// alert(" sucess ..");
							}
						});
					}
				}]
	});

};
